我的目标是将http://localhost/web1
redirect到http://localhost:5000/
。 我是nginx新手,日志给了我。 localhost:5000正在运行。 如果它可能是问题的一部分(nginx:阿尔派),我在docker上运行它?
$curl localhost:5000 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
日志:
2017/01/14 11:32:24 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /web1 HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "localhost" 172.18.0.1 - - [14/Jan/2017:11:32:24 +0000] "GET /web1 HTTP/1.1" 502 537 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" "-"
configuration:
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location /web1 { proxy_set_header Host $host; proxy_pass http://127.0.0.1:5000/; } location /web2 { proxy_set_header Host $host; proxy_pass http://127.0.0.1:5001/; } }
我在nginx中使用rewrite
的重定向,我想你应该尝试这样的事情:
location /web1 { rewrite ^/(.*)$ $scheme://127.0.0.1:5000/$1 permanent; }
在我的机器上工作,希望它会帮助你!