我使用闪亮的服务器在端口 3838 上构建一个 Web 应用程序,当我在服务器中使用 nginx 时,它运行良好。但是当我在服务器上停止 nginx 并尝试使用 docker nginx 时,我发现该站点出现“502-Bad Gate Way”错误,并且 nginx 日志显示:
2016/04/28 18:51:15 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, ...
我通过以下命令安装 docker-nginx:
sudo docker pull nginx
我的 docker 命令行类似于(为了清楚起见,我添加了一些缩进):
sudo docker run --name docker-nginx -p 80:80
-v ~/docker-nginx/default.conf:/etc/nginx/conf.d/default.conf
-v /usr/share/nginx/html:/usr/share/nginx/html nginx
我在我的主目录中创建一个名为“docker-nginx”的文件夹,将我的 nginx conf 文件移到此文件夹中,然后删除 etc/nginx 目录中的原始conf以防万一。
我的 nginx conf 文件如下所示:
server {
listen 80 default_server;
# listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
proxy_pass http://127.0.0.1:3838/;
proxy_redirect http://127.0.0.1:3838/ $scheme://$host/;
auth_basic "Username and Password are required";
auth_basic_user_file /etc/nginx/.htpasswd;
# enhance the performance
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
您必须直接定义上游。目前您的 nginx 无法代理您的 Web 应用程序。
http://nginx.org/en/docs/http/ngx_http_upstream_module.html http://nginx.org/en/docs/http/ngx_http_upstream_module.html
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
server {
location / {
proxy_pass http://backend;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)