【问题标题】:Mac Nginx. Can't change the default pageMac Nginx。无法更改默认页面
【发布时间】:2015-04-22 18:43:46
【问题描述】:

很遗憾,我的 nginx 默认页面设置无法正常工作。我已经删除了 /var/www/ 中所有预装的 html 文件,但它仍然可以加载默认的..(也清除了浏览器缓存)

我当前的文件:

nginx.conf

    worker_processes  1;

error_log  /usr/local/etc/nginx/logs/error.log debug;

events {
    worker_connections  1024;
}

http {
include             mime.types;
default_type        application/octet-stream;

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  /usr/local/etc/nginx/logs/access.log  main;

sendfile            on;

keepalive_timeout   65;

index index.html index.php;

include /usr/local/etc/nginx/sites-enabled/*; 
}

网站可用/默认

    server {
listen       80;
server_name  localhost;
root       /var/www/;

access_log  /usr/local/etc/nginx/logs/default.access.log  main;

location / {
    include   /usr/local/etc/nginx/conf.d/php-fpm;
}

error_page  404     /404.html;
error_page  403     /403.html;
}

sites-enabled 包含 sites-available 中文件的别名。

希望我没有错过任何东西!

提前非常感谢您! :)

【问题讨论】:

  • 考虑到你把所有东西都扔给了php-fpm,显示的是什么页面? (我想知道 PHP-FPM 是否正在从某个地方提取默认文件。)
  • @kyl191 我使用了以下指南。 blog.frd.mn/… 我怎么知道这个默认页面是从哪里拉出来的?我已经将我所有的 php 文件放入 /var/www/ 任何解决方案?谢谢
  • 这个默认页面是什么?你能链接到它的截图吗?访问和错误日​​志是否说明了什么?
  • 副手,我唯一能想到的就是你应该尝试在include /usr/local/etc/nginx/conf.d/php-fpm; 指令下面添加try_files $uri =404,看看你是否可以访问任何静态资源/页面。 (即,只需将任何文件放在 /var/www 中,看看是否可以使用 localhost/file.ext 访问它)
  • @kyl191 这是我当前默认页面的截图:imgur.com/rGYPtuW 它是由上面链接的教程设置的。强制执行 404 时,错误日志显示 2015/04/23 22:12:12 [error] 850#0: *4 open() "/var/www404" failed (2: No such file or directory), client: 127.0 .0.1,服务器:localhost,请求:“GET /index.php HTTP/1.1”,主机:“localhost”(为什么它重定向到 /var/www404 而不是 /var/www/404.php - 注意:我改变了将文件类型从 html 转换为 PHP)。插入 try_files 时,即使在现有文件上也会出现连接错误!nginx 启动后(错误日志):imgur.com/lvt4mgn

标签: macos nginx settings default


【解决方案1】:

好的...让我们试试这个:

usr/local/etc/nginx/sites-available/default 中,将整个location / 块替换为

location / {
  try_files $uri $uri/ /index.php$is_args$args;
}

这告诉 nginx 首先查找命名文件,然后查找具有该名称的目录,最后将其传递给 index.php。 (想了解更多关于nginx如何进行位置块匹配,我建议this Digital Ocean article。)

然后,在/usr/local/etc/nginx/conf.d/php-fpm 中,删除try_files $uri = 404; 行。

我很确定这是导致/var/www404 查找的行,因为= 404 之间不应该有空格。此外,该部分中的 try_files 并没有做太多。

至于从哪里提取内容,“克隆我的示例虚拟主机”步骤是将 index.html 复制到 /var/www

【讨论】:

  • 已完成步骤,也感谢您的文章。不幸的是,我无法解决问题:调用 localhost 仍然显示默认页面,并且像 localhost/index.php 这样的 url 总是抛出 500 Internal Server Error。错误日志写入以下内容:[error] 617#0: *4 rewrite or internal redirect cycle while internal redirecting to "/index.php", client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1”,主机:“本地主机”。由于它从 /var/www/index.html 中提取默认页面(已删除),我不明白它是如何捕获它的。
  • 在这种情况下,我会说擦除所有内容并重试教程。默认页面异常持久的事实毫无意义。值得gist.github.com/kyl191/ac8a77ddc0791fc28c95 是我的 nginx 配置。
  • 感谢您的帮助!我要重新安装所有这些东西,然后再试一次。
猜你喜欢
  • 1970-01-01
  • 2018-02-28
  • 1970-01-01
  • 2013-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多