【问题标题】:NGINX images not displayingNGINX 图像不显示
【发布时间】:2022-03-08 15:52:01
【问题描述】:

谁能告诉我为什么 NGINX 不在我的“img”文件夹中显示我的图像?它激怒了我的生活。 Apache“开箱即用”。我到处都找不到一个简单的答案。有人可以解释一个简单的解决方案。我的 CSS 文件正在运行,它们位于带有 index.php 的根文件夹中,但很明显,NGINX 除了服务器根文件夹之外没有其他地方

【问题讨论】:

  • 肯定有什么配置错误,但没有显示的配置,我们将无法提供帮助......
  • 为什么 nginx 应该看起来“除了服务器根文件夹之外的任何地方”?您是否已将服务器配置为这样做?这对于包含图像的文件夹意味着什么?
  • 您的/etc/nginx/nginx.conf 设置是什么?应该有一行include /etc/nginx/mime.types;,需要取消注释才能让nginx识别地雷类型。

标签: php html css nginx


【解决方案1】:

试试这个 Nginx 设置,

    server {
    listen 80;
    server_name server_domain_or_IP;
    root /var/www/travellist/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
   }

【讨论】:

    【解决方案2】:

    您不能在同一台机器上安装两个 Web 服务器(NGINX 和 Appach),这就像拥有两个软件防火墙,它们将无法正常工作。 如果 NGINX 配置良好,请停用 Appach。

    【讨论】:

    • 因为它们都是两个Web服务器,会在机器上产生冲突。一台机器上只能有一个网络服务器
    • 如果你想同时保留它们,让它们监听不同的端口,因为默认的网络端口是 80
    • 这与问题有什么关系?为什么您认为两台服务器都在运行而用户无法正确配置它们?
    猜你喜欢
    • 2018-01-01
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    相关资源
    最近更新 更多