我无法重定向https://example.org到https://www.example.org,我的配置如下:
server {
listen 443;
server_name www.example.org;
#
#more configuration here;
#
}
server {
listen 443;
server_name example.org;
return 301 https://www.example.org$request_uri;
}
答案1
return 301 https://www.example$request_uri;
^^^^
也许,少了一个.org
?
答案2
所以这个配置对我来说是有效的,我错过了SSL 标志在配置上。谢谢 阿列克谢十以获得洞察力。
## Main configuration
server {
listen 443;
ssl on;
server_name www.example.org;
ssl_certificate /home/user/example.org/example.org.crt;
ssl_certificate_key /home/user/example.org/example.org.key;
#
#more configuration here;
#
}
## Redirect
server {
listen 443;
server_name example.org;
ssl on;
ssl_certificate /home/user/example.org/example.org.crt;
ssl_certificate_key /home/user/example.org/example.org.key;
return 301 https://www.example.org$request_uri;
}