【问题标题】:https static content on NGINXNGINX 上的 https 静态内容
【发布时间】:2016-07-21 23:07:18
【问题描述】:

我从一位同事那里继承了一个配置,用于安装 NGINX 的 VPS。我目前可以通过 http 和 https 提供动态内容,但是当 https 被指定为连接类型时,不会加载图像、javascript 和 css 等静态内容(显示为 404)。

由于我继承了配置,我不太确定从哪里开始,尽管我没有成功地尝试过 NGINX 自己的指南,即在 http 指令下向 nginx.conf 添加位置块,指定要使用的根目录。

http{
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  server_tokens off;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    location / {
      root /var/www/;
    }
}

在禁用 NGINX 的情况下,我也确实遇到了同样的行为,但是我无法在我的同事注释中找到任何关于其他可能提供内容的文档。

任何正确方向的指针将不胜感激!

nginx.conf

user              nginx;
worker_processes  1;
error_log         /var/log/nginx/error.log;
pid               /var/run/nginx.pid;

events {
    worker_connections  1024;
}



http {

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_tokens off;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request "'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    autoindex off;
    map $scheme $fastcgi_https { ## Detect when HTTPS is used
        default off;
        https on;
    }


client_header_timeout 3000;
client_body_timeout 3000;
fastcgi_read_timeout 3000;
client_max_body_size 32m;
fastcgi_buffers 8 128k;
fastcgi_buffer_size 128k;

    keepalive_timeout  10;

gzip  on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

}

【问题讨论】:

  • http 中的 location 无效。显示您的服务器配置
  • 我在原帖中添加了 nginx.conf
  • 我没有看到任何 server 块。它们应该在/etc/nginx/conf.d/*.conf; 文件中
  • 我发现我得到 404 的原因是“internal-nginx-static-location”的字符串值被添加到请求中,但我无法查看它的定义位置。

标签: nginx vps


【解决方案1】:

通过这个我发现NGINX一直在向服务器添加一个命令>> x-accel-internal的位置块。

通过将模板 proxy.php 从 conf/templates/default/domain/service 复制到 custom/domain/service 并注释掉此命令,nginx 在通过 SSH 重新创建配置文件后再次正确地提供内容

/usr/local/psa/admin/bin/httpdmng --reconfigure-all
nginx -t && service nginx reload

【讨论】:

    猜你喜欢
    • 2019-02-01
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 2020-09-17
    相关资源
    最近更新 更多