使用 docker 配置 Nginx,配置 ssl 后 521

2023-06-16 20:43:10 +08:00
 z8596007

第一次使用 docker 容器化部署

nginx 也部署在 docker 上

使用了 cloudflare 。开启 ssl 页面就显示 521 使用端口访问没问题。 哪位大神帮忙看看是怎么回事

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    log_format main
    '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log main;
    sendfile on;
    keepalive_timeout 65;


    upstream www {
        server 172.20.0.2:3000;
    }
    upstream api {
        server 172.20.0.3:4000;
    }
    server {
        listen 80;
        listen [::]:80;
        server_name netcore.pub www.netcore.pub;
        return 301 https://www.netcore.pub$request_uri;
    }
    server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name netcore.pub www.netcore.pub;
        ssl  on;
        ssl_certificate   /etc/nginx/ssl/netcore.pem; 
        ssl_certificate_key    /etc/nginx/ssl/netcore.key;
        

        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            proxy_pass http://www;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /api {
            proxy_pass http://api;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

Nginx 启动命令

docker run -d \                                                             
--name nginx \
-p 80:80 \
--restart=always \
-v /usr/local/docker_data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/docker_data/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /usr/local/docker_data/nginx/html:/usr/share/nginx/html \
-v /usr/local/docker_data/nginx/logs:/var/log/nginx \
-v /usr/local/docker_data/nginx/conf/ssl:/etc/nginx/ssl \
nginx
670 次点击
所在节点    问与答
4 条回复
z8596007
2023-06-16 20:51:39 +08:00
有人吗?
yinmin
2023-06-16 21:23:16 +08:00
docker run 的 443 端口没映射出来
yaott2020
2023-06-16 21:30:11 +08:00
加个--network host
z8596007
2023-06-16 21:32:41 +08:00
@yinmin 好像是这么回事。谢谢~~

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/949403

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX