编程爱好者之家

nginx反向代理配置

2019-11-20 11:58:40 266


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

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


以下是我的配置文件:

server {
        listen   83;//端口号就是刚才在防火墙添加的端口号
        server_name www.codelovers.cn codelovers.cn ;
        root /home/code/www.codelovers.cn;
        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 ^/(.*)$ http://www.itbiancheng.com/$1 permanent;
         }
        location ~* ^/(uploadimg|uploads)/.*.(php|php5)$ {
          deny all;
        }

    if (!-e $request_filename)

    { 
        rewrite ^/([a-zA-Z]+)$ /$1/ 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.3:83;//192.168.1.3 根据实际情况更改成自己的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;
    }

}


同类文章