第一次使用 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
1
z8596007 OP 有人吗?
|
2
yinmin 2023-06-16 21:23:16 +08:00 via iPhone
docker run 的 443 端口没映射出来
|
3
yaott2020 2023-06-16 21:30:11 +08:00 via Android
加个--network host
|