ssl - 如何在 nginx 上将 HTTPS 设置为默认

标签 ssl nginx https

我有启用 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/

相关文章:

ios - 即使在手动安装证书后也无法在 iOS 模拟器上通过 SSL 握手

node.js - Nginx 多个负载均衡器或单个负载均衡器

nginx - 为什么 nginx 总是以默认站点响应,即使它现在应该响应?

https - 如何使用 https 运行 Vue.js 开发服务?

https - 让 wildfly 监听端口 443 而不是 8443

apache - 我可以为所有 VirtualHost 使用一个 SSLCertificateFile,而不是为每个 VirtualHost 创建一个 SSLCertificateFile 吗?

c# - 如何测试 SSL/TLS 底层是否正常工作

node.js - 使用 ioRedis 连接到 ElastiCache 时出现随机 SSL 握手错误

nginx - 为除某些文件外的所有 js 和 css 设置 Nginx 过期 header

Node.js OpenStack Swift 插件连接错误