安装依赖
PCRE – Supports regular expressions. Required by the NGINX Core and Rewrite modules.
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -zxf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install
zlib – Supports header compression. Required by the NGINX Gzip module.
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
OpenSSL – Supports the HTTPS protocol. Required by the NGINX SSL module and others.
wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
tar -zxf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
./Configure darwin64-x86_64-cc --prefix=/usr
make
make install
下载Nginx
wget https://nginx.org/download/nginx-1.17.9.tar.gz
tar zxf nginx-1.17.9.tar.gz
cd nginx-1.17.9
编译
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre=../pcre-8.44 --with-zlib=../zlib-1.2.11 --with-http_ssl_module --with-stream --with-mail=dynamic --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module
make
make install
NGINX systemd service file
nano /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx.pid
ExecStartPre=/usr/local/nginx/nginx -t
ExecStart=/usr/local/nginx/nginx
ExecReload=/usr/local/nginx/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
测试配置文件:/usr/local/nginx/nginx -t
启动:systemctl start nginx.service
停止:systemctl stop nginx.service
重启:systemctl restart nginx.service
查看状态:systemctl status nginx.service
反代gist
在/usr/local/nginx/nginx.conf
中的http块中插入如下一段
server {
listen 443 ssl;
server_name gist.example.com;
ssl_certificate /etc/ssl/server.crt;
ssl_certificate_key /etc/ssl/server.key;
access_log off;
resolver 1.0.0.1;
location / {
proxy_pass https://gist.github.com;
proxy_set_header Accept-Encoding "";
proxy_set_header Accept-Language "zh-CN";
proxy_set_header User-Agent $http_user_agent;
sub_filter https://gist-assets.github.com/ https://gist.example.com;
sub_filter https://gist.github.com/ https://gist.example.com;
sub_filter_once off;
}
}
实测可以套Cloudflare(我仅测试了套cfp)