当前位置:首页 > Liunx教程 >

nginx反向代理配置

发布时间:2018-09-29 17:39:01 作者:佚名 阅读:(179)

今天吾爱编程的一个项目用到了反向代理,接下来就介绍一下nginx反向代理的方法,有需要的小伙伴可以参考一下:

在防火墙添加需要的端口
文件路径:/etc/sysconfig/iptables
-A INPUT -s 192.168.1.204 -p tcp -m tcp --dport 83 -j ACCEPT  //-s 192.168.1.204 是指定固定ip访问

端口添加好之后,重启防火墙
把要走代理的域名的nginx复制一份出来www.itbiancheng.com.83.conf

以下是我的配置文件:
server {
        listen   83;//端口号就是刚才在防火墙添加的端口号
        server_name www.itbiancheng.com itbiancheng.com ;
        root /home/wwwroot/www.itbiancheng.com;
        index index.php index.html;
        fastcgi_intercept_errors on;
        error_page   500 502 503 504  /50x.html;
        error_page 404 /404.html;
        location = /50x.html {
                root   /var/www/nginx-default;
        }
        include enable-php.conf;
        if ($host = 'itbiancheng.com') {
            rewrite ^/(.*)$ https://www.itbiancheng.com/$1 permanent;
         }
        location ~* ^/(uploadimg|uploads)/.*.(php|php5)$ {
          deny all;
        }

    if (!-e $request_filename)

    { 
        rewrite ^/([a-zA-Z]+)$ /$1/ permanent;
        #换栏目重定向
        rewrite ^/news/60925.html /langrensha/60925.html permanent;
        rewrite ^/news/66860.html /langrensha/66860.html permanent;
        rewrite ^/news/63276.html /yulu/zaoanxinyu/63276.html permanent;
    }
    access_log  off;
}
代理机nginx设置:
server {
   listen 80;
    server_name  www.itbiancheng.com itbiancheng.com;
    location / {
        access_log off;
        proxy_pass             http://192.168.1.204:83;//192.168.1.204 根据实际情况更改成自己的IP,端口号是上面设置的
        proxy_connect_timeout 300s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;
        proxy_set_header       Host $http_host;
        proxy_set_header       X-Real-IP $remote_addr;
        proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

欢迎分享转载→ nginx反向代理配置

© 2015-2021 - 吾爱编程网 版权所有 苏ICP备18033726号-1关于我们 - 网站声明 - 联系我们