Nginx ssl连接

时间:2016-02-15 12:31:34

标签: nginx

我正在尝试使用nginx ssl连接来服务安全站点。我无法加载第三方http css和js文件。这是错误的。

 This request has been blocked; the content must be served over HTTPS.

这是我的nginx conf

server {
listen 443 ssl;
server_name api-test.vendorver.com;
ssl_certificate     /etc/nginx/ssl/vv_key/cert_chain.crt;
ssl_certificate_key /etc/nginx/ssl/vv_key/vendorver.key;
ssl_protocols    TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
location / {
    proxy_pass http://0.0.0.0:8000;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_redirect off;
}
#if ($host !~* ^(vendorver.com|www.vendorver.com)$ ) {
#    return 444;
#}
location /static/ {
    autoindex on;
    alias /home/ec2-user/vendorver.backend/static/;
}
}

该文件在https请求中不可用。如何在页面中包含该文件?

2 个答案:

答案 0 :(得分:0)

您必须配置静态目录和媒体(图像)目录 要在ssl上运行所有这些,配置应该是这样的:

23

答案 1 :(得分:0)

而不是在同一配置中同时监听端口80和443。我建议设置服务器重定向,例如

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

Setting up SSL with nginx including redirects from non HTTPS traffic