The directory access problem of Nginx reverse proxy

Source: Internet
Author: User
Tags nginx reverse proxy

 The Directory Access problem of Nginx reverse proxy2013-05-13 23:21 2730 People read comments (0) favorite reports

Since yesterday began to tangle, in doing experiments, encountered directory access problems, as follows

The front-end Nginx Vhost is set as follows, and the proxy accesses the backend 192.168.0.37

Server    {            listen  ;            server_name  www.proxy.com;            Index index.php index.html index.htm;            location/test/{                proxy_next_upstream http_502 http_504 error timeout invalid_header;                Proxy_pass http://192.168.0.37;                Proxy_set_header Host 192.168.0.37;                Proxy_set_header x-forwarded-for $remote _addr;                Proxy_redirect http://192.168.0.37/test//test/;            }             Access_log/data/logs/weblog/proxy_server.access.log;}

The back end of the 192.168.0.37 in the root directory is the test directory, the directory has an index file, the content is "192.168.0.37 proxy test ok!"

The problem now is if you have access to the www.proxy.com/test/, as follows

[CSharp]View Plaincopyprint?
    1. [[email Protected]_node ~]# curl-i http://www.proxy.com/test/
    2. http/1.1 OK
    3. Server:nginx
    4. date:wed, APR 04:22:40 GMT
    5. content-type:text/html; Charset=utf-8
    6. Content-length:28
    7. Connection:keep-alive
    8. last-modified:wed, APR 03:09:13 GMT
    9. Accept-ranges:bytes

But if you visit Www.proxy.com/test, you'll be 301.

[CSharp]View Plaincopyprint?
    1. [[email Protected]_node ~]# curl-i http://www.proxy.com/test
    2. http/1.1 301 Moved Permanently
    3. Server:nginx
    4. date:wed, APR 04:25:01 GMT
    5. Content-type:text/html
    6. content-length:178
    7. Location:http://www.proxy.com/test/
    8. Connection:keep-alive

I just started to think it was my front end of the Proxy_redirect setup has a problem, later modified proxy_redirect many times, can not meet the requirements, the last whim, the front-end of the nginx set into such

[CSharp]View Plaincopyprint?
  1. Server
  2. {
  3. Listen 80;
  4. server_name www.proxy.com;
  5. Index index.php index.html index.htm;
  6. location/test {
  7. Proxy_next_upstream http_502 http_504 error timeout invalid_header;
  8. Proxy_pass http://192.168.0.37/test/;
  9. Proxy_set_header Host 192.168.0.37;
  10. Proxy_set_header x-forwarded-for $remote _addr;
  11. #proxy_redirect http://192.168.0.37/test//test/;
  12. }
  13. Location/{
  14. Proxy_next_upstream http_502 http_504 error timeout invalid_header;
  15. Proxy_pass http://192.168.0.37/;
  16. Proxy_set_header Host 192.168.0.37;
  17. Proxy_set_header x-forwarded-for $remote _addr;
  18. }
  19. Access_log/data/logs/weblog/proxy_server.access.log;
  20. }

In that case, there's no problem accessing www.proxy.com/test.

[CSharp]View Plaincopyprint?
    1. [Email protected]_node vhosts]# Curl Www.proxy.com/test
    2. 192.168.0.37 Proxy Test ok!

The directory access problem of Nginx reverse proxy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.