第一次使用 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
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.