Lnmp1.3反响代理办法

首先下载扩展:ngx_http_substitutions_filter_module

cd /tmp  
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

进入 lnmp1.3-full 编辑lnmp.conf,在Nginx扩展中添加内容:

Nginx_Modules_Options='--add-module=/tmp/ngx_http_substitutions_filter_module'  

保存退出

用升级脚本升级nginx:

./upgrade.sh nginx  

输入nginx版本,比如1.8.1,然后开始升级.

升级nginx完毕后我们查看nginx扩展nginx -V,如果以上几个扩展全都加上去了就对了.

server {    
        listen 80;    
        server_name www.aaaaa.com;    
        index index.php index.html index.htm;    
    
        location / {    
        default_type text/html;    
        subs_filter_types text/css text/xml;   
        subs_filter 'http://www.bbbbbb.com' 'http://www.aaaaa.com' g;    
        proxy_set_header X-Real-IP  $remote_addr;    
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
        proxy_set_header Referer http://www.bbbbbb.com;    
        proxy_set_header Host www.bbbbbb.com;    
        proxy_pass http://www.bbbbbb.com;   #被代理网站的网址    
        proxy_set_header Accept-Encoding "";    
        }    
}    

Https 代理方法:

server {  
        listen 443 ssl;  
        ssl on;  
        ssl_certificate /usr/local/nginx/conf/ssl/www.aaaaa.com.crt;  
        ssl_certificate_key /usr/local/nginx/conf/ssl/www.aaaaa.com.key;  
        server_name www.aaaaa.com;  
        index index.php index.html index.htm;  
  
        location / {  
        default_type text/html;  
        subs_filter_types text/css text/xml;  
        subs_filter 'http://www.bbbbbbb.com' 'https://www.aaaaa.com' g;  
        proxy_set_header X-Real-IP  $remote_addr;  
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
        proxy_set_header Referer http://www.bbbbbbb.com;  
        proxy_set_header Host www.bbbbbbb.com;  
        proxy_pass http://www.bbbbbbb.com;  #被代理网站的网址  
        proxy_set_header Accept-Encoding "";  
        }  
}  

主要就是删除

listen 80;  

添加:

listen 443 ssl;  
ssl on;  
ssl_certificate /usr/local/nginx/conf/ssl/www.aaaaa.com.crt;  
ssl_certificate_key /usr/local/nginx/conf/ssl/www.aaaaa.com.key;  

要注意.crt和.key的路径和名字一定不要错了。

然后在subs_filter替换中将代理的域名从http://改变成https://

Lnmp1.3代理办法

如果使用https反代的时候出现访问默认页面
可以使用cloudflare作为https的cdn并取消443端口改为80端口:

server {  
        listen 80;  
        server_name www.aaaa.com;  
        index index.php index.html index.htm;  
  
        location / {  
        default_type text/html;  
        subs_filter_types text/css text/xml;  
        subs_filter 'http://api.ccccccc.com' 'https://api.ccccccc.com' g;  
        subs_filter 'http://www.bbbbbbb.com' 'https://www.aaaa.com' g;  
        proxy_set_header X-Real-IP  $remote_addr;  
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
        proxy_set_header Referer http://www.bbbbbbb.com;  
        proxy_set_header Host www.bbbbbbb.com;  
        proxy_pass http://www.bbbbbbb.com;  #被代理网站的网址  
        proxy_set_header Accept-Encoding "";  
        }  
}  

参考文章:

LNMP安装GOOGLE反代扩展和一键脚本_空间域名
http://www.mfbuluo.com/24463.html

LNMP一键包环境安装SSL安全证书且部署HTTPS网站URL过程 | 老左博客
http://www.laozuo.org/5571.html


 继续浏览关于 技术 的文章

 本文最后更新于 2019/07/21 02:48:55,可能因经年累月而与现状有所差异

 引用转载请注明:icret > 教程 > Lnmp1.3反响代理办法