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?
- [[email Protected]_node ~]# curl-i http://www.proxy.com/test/
- http/1.1 OK
- Server:nginx
- date:wed, APR 04:22:40 GMT
- content-type:text/html; Charset=utf-8
- Content-length:28
- Connection:keep-alive
- last-modified:wed, APR 03:09:13 GMT
- Accept-ranges:bytes
But if you visit Www.proxy.com/test, you'll be 301.
[CSharp]View Plaincopyprint?
- [[email Protected]_node ~]# curl-i http://www.proxy.com/test
- http/1.1 301 Moved Permanently
- Server:nginx
- date:wed, APR 04:25:01 GMT
- Content-type:text/html
- content-length:178
- Location:http://www.proxy.com/test/
- 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?
- Server
- {
- Listen 80;
- 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/test/;
- 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/;
- }
- Location/{
- 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;
- }
- Access_log/data/logs/weblog/proxy_server.access.log;
- }
In that case, there's no problem accessing www.proxy.com/test.
[CSharp]View Plaincopyprint?
- [Email protected]_node vhosts]# Curl Www.proxy.com/test
- 192.168.0.37 Proxy Test ok!
The directory access problem of Nginx reverse proxy