问题原文
原帖链接 · Richard87 · CC BY-SA 3.0
I have a simple config, redirect everything except letsencrypt requests to https, and then have my virtual hosts only on https..
Currently all my requests are redirected to https, and then a 404 for letsencrypt:
This is my config...
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location ^~ /.well-known/acme-challenge/ {
allow all;
default_type text/plain;
return 200 "$1.abcd-efgh";
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name plex.my_domain.com;
ssl_session_timeout 30m;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_certificate /root/.acme.sh/plex.my_domain.com/fullchain.cer;
ssl_certificate_key /root/.acme.sh/plex.my_domain.com/plex.my_domain.com.key;
ssl_session_cache shared:SSL:10m;
add_header X-Xss-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Strict-Transport-Security "max-age=2592000; includeSubdomains" always;
add_header X-Frame-Options "SAMEORIGIN" always;
proxy_hide_header X-Powered-By;
add_header 'Referrer-Policy' 'no-referrer';
add_header Content-Security-Policy "frame-ancestors my_domain.com plex.my_domain.com;";
location / {
proxy_pass http://127.0.0.1:32400;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#Next three lines allow websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
已采纳解答
原帖链接 · Tero Kilkanen · CC BY-SA 3.0
You have HSTS headers set in your https server block. This means that if you visit your site with https once with your browser, your browser will always connect to your domain with https after the first visit.
This means that you cannot test your configuration with a browser. You need to test it with curl or similar tool that doesn't store HSTS lists.
There is a minor tweak for your configuration, you can use a simple prefix match location /.well-known/acme-challenge for your LetsEncrypt location. nginx will use the most specific match from the location blocks.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
