如何用nginx做反向代理

2016-11-20 00:31:40 5205

1.nginx/conf目录中创建文件proxy.conf以方便在建立站点的时候引用

 proxy_connect_timeout 300s;

  proxy_send_timeout 900;

  proxy_read_timeout 500;

  proxy_buffer_size 32k;

  proxy_buffers  4 32k;

  proxy_busy_buffers_size 64k;

  proxy_redirect off;

  proxy_hide_header Vary;

  proxy_set_header Accept-Encoding '';

  proxy_set_header host $host;

  proxy_set_header Referer $http_referer;

  proxy_set_header Cookie $http_cookie;

  proxy_set_header X-Real-Ip $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  expires 10d;

2.建立站点

server{

       listen 80;

       #listen [::]:80;

       server_name www.landui.com website.com;

       index index.html index.htm index.php default.html default.htm default.php index.asp default.asp;

       location / {

             #ModSecurityEnabled off;

             #ModSecurityConfig modsecurity.conf;

       }

       location ~ .*.(php)(.*){

             proxy_pass http://www.landui.com;

             include /etc/nginx/proxy.d/proxy.conf;

       }

       location ~ .*.(asp)(.*){

             proxy_pass http://www.landui.com;

             include /etc/nginx/proxy.d/proxy.conf;

       }

       location ~ .*.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {

            #include cache.conf;

            proxy_pass http://www.landui.com ;

            include /etc/nginx/proxy.d/proxy.conf;

        }

}

:代理只是一个中介服务,归根揭底还是要被代理的服务能正常访问还要代理的服务配置正确


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: