ssl - https 需要 url 中的 80 端口

标签 ssl nginx https nginx-reverse-proxy

使用Nginx 1.12.1版本 没有端口,没有指定的 URL 将不适用于 Https,即 https://test.domain.com:80

代码如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        ssl on;
        server_name ~^(?<subdomain>[^.]+)\.domain.com$;

        ssl_certificate /etc/ssl/ssl_certificate.cer;
        ssl_certificate_key /etc/ssl/sslnew.key;

        root /var/www/$subdomain;
        index index.html;
        location / {
                try_files $uri $uri/ =404;

        }

}

如果我删除“SSL on”,那么 https 将无法工作,但它可以在没有端口号的情况下工作,即 test.domain.com。

最佳答案

http 假定端口 80,https 假定端口 443。如果您希望浏览器覆盖这些默认值,则必须在 URL 中指定端口。

正确的解决方案是在端口 80 上提供 http 并在端口 443 上提供 https,在这种情况下,不需要在 URL 中提供端口,可以从方案(httphttps)假定。

例如:

server {
    listen  80;
    listen  443 ssl;
    ...
}

参见 this document了解详情。

关于ssl - https 需要 url 中的 80 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53740092/

相关文章:

JavaMail IMAP 邮件内容 SSL/NON SSL

python - 使用 Python 解析 .pcap 文件中的 SSL 流量

apache - 在使用 mod_rewrite 的 Apache .htaccess 文件中,是否可以为域强制 www 和强制 https?

python - 使用 RTMP 协议(protocol)将视频文件流式传输到使用 Python 的 rtmp 服务器

https - 客户端防火墙阻止除 80 和 443 以外的所有端口,需要将端口 443 上的请求转发到 SSH 或 HTTPS

asp.net - 为什么 Request.IsSecureConnection 在预期为 true 时返回 false

ruby-on-rails - 突然无法推送到 heroku : "unable to negotiate key exchange method"

python - 为什么不以 root 身份运行 uwsgi 实例

django - 如何在安装了python 3.4的情况下使用python 2.7在nginx和virtualenv上使Django 1.7在Ubuntu 14.04上正常工作?

java.lang.ClassCastException : libcore.net.http.HttpURLConnectionImpl 无法转换为 javax.net.ssl.HttpsURLConnection