gpt4 book ai didi

web-services - 连接到上游时 docker nginx 连接被拒绝

转载 作者:行者123 更新时间:2023-12-02 21:04:28 25 4
gpt4 key购买 nike

我使用 Shiny 的服务器在端口 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

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;
}
}

关于web-services - 连接到上游时 docker nginx 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36923214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com