gpt4 book ai didi

redirect - 域的 SSL,包括子域

转载 作者:太空宇宙 更新时间:2023-11-03 14:50:16 24 4
gpt4 key购买 nike

我有一个域,example.com。由此,我有这些:

  • blog.example.com
  • api.example.com
  • books.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;
}

blog.example.com 的 nginx 配置文件

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
  • ALL http://请求子域重定向到各自的 https://版本
  • 如果请求的子域不存在,它应该重定向到 default_server ( https://example.com )

最佳答案

我没有使用 return,而是在主域及其子域的重定向服务器 block 上使用 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;
}

This link helped

关于redirect - 域的 SSL,包括子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34983456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com