我有一个域example.com
。从那以后,我有这些:
我已经获得了根域及其子域的SSL证书。
我希望重定向如此:
这是我的example.com
nginx conf
server {
listen 443 ssl default_server;
root /home/django/khophi;
index index.html index.htm;
server_name example.com;
include /etc/nginx/globalssl.conf; //ssl config
}
server {
listen 80 default_server;
server_name example.com;
return 301 https://$host$request_uri;
}
nginx conf blog.example.com
server {
listen 443 ssl; // now listens for https
root /var/www/html/blog;
index index.php index.html index.htm;
server_name blog.example.com;
#include /etc/nginx/globalssl.conf;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
// error pages
location ~ \.php$ {
//php specific things
}
}
server {
listen 80;
server_name blog.example.com;
return 301 https://blog.example.com$request_uri;
}
books.example.com
遵循与blog.example.com
conf
上述设置会怎样?
http://example.com
重定向到https://example.com
(就像我想要的那样http://blog.example.com
重定向至https://blog.example.com
但,显示https://example.com
页面就我而言,我想:
example.com
保留为default_server
http://example.com
重定向到https://example.com
答案 0 :(得分:0)
我使用return
而不是使用rewrite
代替主域及其子域上的重定向服务器块,如下所示:
// blog.example.com
server {
listen 80;
server_name blog.example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
// example.com
server {
listen 80 default_server;
server_name example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}