未找到NGINX索引404

时间:2018-01-20 13:57:47

标签: php nginx ghost

我刚刚在运行NGINX的新服务器上安装了Ghost Blog。 Ghost config.json文件指向正确的目录/博客,当我访问它时,博客加载正常。

什么不起作用,当我从网址中删除/博客时,我将被带到404页面。我已经检查了我的网站启用文件,如下所示:

server {
listen 80;
listen [::]:80;

server_name *********;
root /var/www/ghost/system/nginx-root;

location ^~ /blog {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://*********:2368;
    proxy_redirect off;
}

location ~ /.well-known {
    allow all;
}

client_max_body_size 50m;

但是我不能完全确定我需要改变什么才能得到404错误。我有一个示例.php文件应该加载,但不是。

我一直使用Digital Ocean One-Click Ghost应用程序,但我想这次使用Ghost CLI。我有一种感觉,我已经错过了一些东西。

2 个答案:

答案 0 :(得分:0)

以下内容可能会删除您的部分限制,但可以使用

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/thedomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/thedomain.com/privkey.pem;

    access_log /var/log/nginx/thedomain.access.log;
    error_log  /var/log/nginx/thedomain.error.log;

    root            /var/www/thedomain;

    index           index.html;

    gzip on;
    gzip_proxied any;
    gzip_types text/css text/javascript text/xml text/plain application/javascript application/x-javascript application/json;

    location / {
        try_files   $uri $uri/ =404;
    }
}

您需要确保所有ssl文件都在那里并且允许通过www-data访问。

如果你需要第一次运行certbot,只需要在没有ssl语句的80块中的443代码

答案 1 :(得分:0)

您发布的nginx配置仅处理Ghost。

您已在端口80上设置服务器响应,将根设置为Ghost的nginx-root,并创建了2个位置块。一个用于/blog/并且服务于Ghost,第二个.well-known块用于处理使用letsencrypt生成SSL证书。

我不是为PHP配置nginx的专家,但this guide from Digital Oceanthis stackoverflow question涵盖了很多细节。

我认为你有几个选择:

  1. 将索引设置为index.php
  2. /添加一个新的位置块,用于提供php文件
  3. 添加一个块来处理所有php文件
  4. 我相信像这样添加一个新的位置块将意味着如果URL中的路径匹配,将始终调用您拥有的任何.php文件。

    location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
    }
    

    但fastcgi_pass的价值取决于你在系统上如何设置PHP。

    有了这个,去/index.php就可以了。

    设置index: index.php意味着/映射到/index.php我不确定这是否会影响Ghost,如果确实如此,则需要特定location / {}阻止而不是设置索引。