Ubuntu:HTTPS 不适用于 Nginx

标签 ubuntu ssl nginx https webserver

我已使用以下内容创建 SSL 证书。

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/cerf.key -out /etc/nginx/ssl/cerf.pem

我还有以下 nginx 配置。 http 在端口 8002 上工作正常。但是,https 根本不工作。 nginx conf 和 SSL 证书位于同一文件夹中。

upstream django {
    server unix:////var/www/dj_test_prj/dj_test_prj/site.bot.sock; # for a file socket
    #server 127.0.0.1:8000; # for a web port socket (we will use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8002;
    # the domain name it will serve for
    server_name .example.com; # substitute your machine IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias  /var/www/dj_test_prj/media;  # your Django project  media files - amend as required
    }

    location /static {
        alias  /var/www/dj_test_prj/static; # your Django project  static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /var/www/dj_test_prj/dj_test_prj/uwsgi_params.bot; # the uwsgi_params file you installed
    }
}


server {
    listen 443;
    server_name .example.com; # substitute your machine IP address or FQDN
    charset     utf-8;

    ssl on;
    ssl_certificate cert.pem;
    ssl_certificate_key cert.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    ssl_prefer_server_ciphers on;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias  /var/www/dj_test_prj/media;  # your Django project  media files - amend as required
    }

    location /static {
        alias  /var/www/dj_test_prj/static; # your Django project  static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /var/www/dj_test_prj/dj_test_prj/uwsgi_params.bot; # the uwsgi_params file you installed
    }

最佳答案

首先,nginx的错误日志写了什么??? 必须首先检查日志,并应将其附加到问题中。

如我所见,您在配置 cert.key 时创建了 cerf.keycerf.crt 文件cert.crt - 这会导致 nginx 启动失败。请向我们展示 sudo nginx -t 输出。

关于Ubuntu:HTTPS 不适用于 Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37217697/

相关文章:

ubuntu - 线程 "main"java.awt.HeadlessException 中的异常

sorting - 在 Hadoop(单节点集群)上运行排序示例

php - 如何使用 ffmpeg 在 30 秒内从较小/较大文件中提取 30 秒音频

ssl - CURL:(35)Ubuntu 服务器的 SSL 连接错误

python - 在没有 proxy_pass 的情况下使用 Nginx 服务 Django 站点

wordpress - 使用多个Docker容器设置Nginx的问题

ubuntu - 在 Ubuntu 上安装 python-twisted 10.2

ssl - EV SSL 证书/更改 WHOIS 企业名称和联系信息

java - 应该使用哪个类在 java 中创建 TLS 连接。套接字类或 SSLSocket 类?

python - 为什么 Unicorn/Gunicorn 提供静态内容的速度很慢?