2
我的目標是將http://localhost/web1
重定向到http://localhost:5000/
。我是nginx新手,日誌給了我。 localhost:5000正在運行。如果它可能是問題的一部分,我在Docker上運行它(nginx:alpine)?從端口80到其他端口的nginx代理
$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" "-"
配置:
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很新 – pethel