我有启用 SSL 的工作域、服务器,它已启动并默认运行 HTTP
。明确地当我请求 https://domain.tld
时它工作正常但是如何将其设置为默认而不是 HTTP
现在我的 nginx 虚拟主机有以下指令
server {
listen 80 ;
listen 443 ssl default_server;
ssl on ;
ssl_certificate /etc/nginx/ssl/XX.crt;
ssl_certificate_key /etc/nginx/ssl/XX.key;
server_name x.me www.x.me;
root /usr/share/nginx/www/x/site;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
最佳答案
将 http 请求重定向到 https。这可以通过脚本来完成,也可以通过使用“return”的 nginx 来完成。
教程:https://christiaanconover.com/blog/how-to-redirect-http-to-https-in-nginx
关于ssl - 如何在 nginx 上将 HTTPS 设置为默认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34746977/