全网影视免费看

Nginx反代服务器反向代理目录代理、页面代理配置规则

nginx服务器下的反向代理的配置步骤比apache服务器稍简单,ngingx只需在需要代理站点配置代理规则就可以了。

(www.test1.com  代理 www.test2.com)

1、全站代理配置(首页也代理)

server {
        listen       80;
        server_name  www.test1.com ;
        root   "D:\PHP\WWW\nginx.com";
         
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
            #反向代理配置
            proxy_pass http://www.test2.com
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

2、全站代理配置(首页不代理)

server {
        listen       80;
        server_name  www.test1.com ;
        root   "D:\PHP\WWW\nginx.com";
         
        #配置首页不代理
        location = / {
        index index.html index.htm index.php
        }
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
            #反向代理配置
            proxy_pass http://www.test2.com
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

3、目录代理配置

server {
        listen       80;
        server_name  www.test1.com ;
        root   "D:\PHP\WWW\nginx.com";
         
        #目录代理 news目录代理 www.test2.com
        location /news/ {
        proxy_pass http://www.test2.com
        }
         
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

 

4、指定类型文件代理配置

server {
        listen       80;
        server_name  www.test1.com ;
        root   "D:\PHP\WWW\nginx.com";
        #指定文件类型代理配置(.shtml、.htm 类型文件代理 www.test2.com)
        location ~ .*\.(shtml|htm)$ {
        proxy_pass http://www.test2.com
        }
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

nginx服务器的指定文件类型反向代理配置时,只配置一种文件类型时,重启服务器的时候报错,导致服务器重启失败,不知道是配置的时候出了点小差错还是这里必须两种以上的类型。

5、首页和html页面使用本地文件代理配置

location  ~* \.(html)$ {  
    root /www/wwwroot/;  
    index index.html; 
}
location = / {
   proxy_pass http://127.0.0.1/index.html;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
本站福利,全网影视在线免费看 | 点击出发

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

提示:非实物交易,购买后不退款,请考虑好再购买 | 点此查看购买指南
售前咨询和售后服务,请点此联系作者咨询

给TA赞赏
共{{data.count}}人
人已赞赏
广告占位
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索