【问题标题】:Unable to connect via https: using below Ngnix configuration无法通过 https 连接:使用下面的 Nginx 配置
【发布时间】:2021-08-16 01:32:53
【问题描述】:

这个配置正确吗?我可以通过 http 访问,但不能通过 https 访问

我在 GCP 计算引擎上的 Ubuntu 20 上安装了 nginx。下面是 nginx 配置文件

server {
    listen 80;
    server_name testprojects.com www.testprojects.com;
    return 301 http://$server_name$request_uri;
}

server {

    listen default_server 443 ssl;

    server_name testprojects.com www.testprojects.com;
    ssl_certificate /home/testprojects_com.crt;
    ssl_certificate_key /home/testprojects_com.key;

    access_log /var/log/nginx/nginx.index.access.log;
    error_log /var/log/nginx/nginx.index.error.log;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    location = /test {
            return test.html;
    }
}

【问题讨论】:

    标签: ubuntu nginx


    【解决方案1】:

    我看到您将http 重定向到https

    你必须httphttps

    也就是说,当任何请求带有http时,只需重定向到https

    改变这一行:

    return 301 http://$server_name$request_uri;
    

    【讨论】:

      猜你喜欢
      • 2019-07-28
      • 2021-09-06
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多