现状:一台云服务器和一个备案域名,服务器在多个非 80 端口拉了容器提供服务,在 80 端口用 Nginx 做反代,没有设置 SSL ,且各服务访问正常
预备:申请了个免费证书,准备给博客的子域名上证书
我的初步预想是,在反代监听 80 和 443 端口,过滤博客的子域名,然后代理到博客容器的端口,拉页面。请教大家这个思路是否正确
然后按照以下配置,访问 http://www.xqmq.icu 时正常,访问 https://www.xqmq.icu 时显示无法访问此页面
请教大家这个应该怎么操作,问题出在哪里了
反代的 nginx.conf
server {
listen 80;
listen 443 ssl;
server_name www.xqmq.icu;
ssl_certificate /etc/nginx/cert/cert.pem;
ssl_certificate_key /etc/nginx/cert/cert.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://xqmq.icu:2690;
}
}
博客的 nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/www/hexo;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
1
GM 2022-02-14 13:17:41 +08:00
server {
listen 443 ssl; ... location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localost:80; } } |
2
totoro625 2022-02-14 13:24:28 +08:00
反代的 nginx.conf ,80 和 443 分开写
server { listen 80; ... } server { listen 443 ssl; ... } |
3
FlyingShark 2022-02-14 14:05:10 +08:00
反代的配置
server { listen 80; listen 443 ssl http2; server_name 你的域名; ssl_certificate 证书路径; ssl_certificate_key 证书私钥路径; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_protocols TLSv1.2; ssl_session_cache shared:SSL:5m; ssl_session_timeout 5m; keepalive_timeout 75s; keepalive_requests 100; access_log /data/你的域名 /log/nginx/access.log; error_log /data/你的域名 /log/nginx/error.log; set_real_ip_from 127.0.0.1; real_ip_header X-Forwarded-For; real_ip_recursive on; add_header Access-Control-Allow-Origin *; if ($scheme = http) { return 301 https://$host$request_uri; } gzip on; gzip_comp_level 6; gzip_min_length 1k; gzip_types text/plain text/css text/xml text/javascript text/x-component application/json application/javascript application/x-javascript application/xml application/xhtml+xml application/rss+xml application/atom+xml application/x-font-ttf application/vnd.ms-fontobject image/svg+xml image/x-icon font/opentype; location / { if ($request_method = OPTIONS) { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; return 204; } proxy_pass http://127.0.0.1:80; proxy_set_header Host 填写后端域名; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; client_max_body_size 10m; } } |
4
snuglove 2022-02-14 15:21:24 +08:00
80 443 写一快是什么写法?
|
5
relaxchen 2022-02-14 15:50:25 +08:00
|
8
dier 2022-02-14 16:50:07 +08:00
```config
server { listen 80; listen 443 ssl; server_name www.xqmq.icu; ssl_certificate /etc/nginx/cert/cert.pem; ssl_certificate_key /etc/nginx/cert/cert.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:2690; # 改成服务器本机访问博客容器的地址和端口就好了 } } ``` |
10
Lockeysama 2022-02-14 16:55:34 +08:00
server {
listen 80; server_name www.xqmq.icu; rewrite ^(.*)$ https://$host$1 permanent; } server { listen 443 ssl; server_name www.xqmq.icu; ... ssl_certificate /etc/nginx/cert/cert.pem; ssl_certificate_key /etc/nginx/cert/cert.key; ... } 基本是差不多这样吧 |
11
xQmQ OP 一枪毙了我得了
跟着几位的设置,又查了一堆文档,中文的英文的,都大差不差的设置,我死活也访问不。折腾了一下午,防火墙、依赖、模块啥都查了个遍,突然一个激灵想起来自己的反代拉的容器,就开了个 80 端口,重开了个 443 ,直接成了 我寻思我还是 remake 了得了太蠢逼了 |
12
xQmQ OP @Lockeysama 嗯嗯,成功了,谢谢
|
14
psydonki 2022-02-15 01:17:02 +08:00
推荐一下 certbot.
我都是直接 certbot ,选择你要部署的域名,它自己就搞定了... |