你好,我是 nginix 新手,我正在尝试做几件事
如果主域名或子域名不是 https 则重定向到 https
加载/读取相应块的位置配置
加载/读取子域配置而不是主域配置
server { if ($host = example.net) { return 301 https://example.net$request_uri; } listen 80; server_name example.net www.example.net; return 301 https://example.net$request_uri; } server { if ($host = in.example.net) { return 301 https://$host$request_uri; } listen 80; server_name in.example.net; return 301 https://in.example.net$request_uri; }
我的主域配置:
server {
server_name example.net;
location / {
proxy_pass http://myip:8089;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
rewrite ^/$ /app/usa/home break;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我的子域名配置:
server {
server_name uk.example.net;
location / {
proxy_pass http://myip:8089;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
rewrite ^/$ /app/uk/home break;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
}
问题:当我加载 uk.example.net 时,它会加载/读取主域(example.net)位置配置
我该如何改善?
我做错了什么?
如果我将来有多个子域名,有什么建议?