简体   繁体   English

找不到NGINX索引404

[英]NGINX Index 404 Not Found

I've just installed a Ghost Blog on a new server running NGINX. 我刚刚在运行NGINX的新服务器上安装了Ghost Blog。 The Ghost config.json file is pointing at the correct directory /blog and the blog loads fine when I visit it. Ghost config.json文件指向正确的目录/ blog,并且在我访问它时博客加载正常。

What isn't working is when I remove /blog from the URL, I get taken to a 404 page. 不起作用的是,当我从URL中删除/ blog时,进入了404页面。 I've checked my sites-enabled file, which looks like this: 我已经检查了启用网站的文件,该文件如下所示:

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;

But I'm not entirely sure what I need to change to not get the 404 error. 但是我不完全确定我需要更改什么才能得到404错误。 I have an example .php file which should be loading but isn't. 我有一个示例.php文件,该文件应该正在加载但不是。

I've always used the Digital Ocean One-Click Ghost app but I wanted to use the Ghost CLI this time round. 我一直使用Digital Ocean一键式Ghost应用程序,但这次我想使用Ghost CLI。 I have a feeling I've missed something though. 我有种想念的感觉。

the following may remove some of your restrictions but it will work 以下内容可能会消除您的一些限制,但可以使用

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;
    }
}

You need to make sure all the ssl files are there and permissioned for access by www-data. 您需要确保所有ssl文件都已存在,并且有权通过www-data访问。

If you need to run certbot for the first time, just but the 443 code in an 80 block without the ssl statements 如果您需要首次运行certbot,请在80块中使用443代码而不使用ssl语句

The nginx configuration you've posted only deals with Ghost. 您发布的Nginx配置仅适用于Ghost。

You've setup a server responding on port 80, set the root to Ghost's nginx-root, and created 2 location blocks. 您已经设置了一个在端口80上响应的服务器,将根设置为Ghost的nginx-root,并创建了2个位置块。 One is for /blog/ and serves Ghost, the second .well-known block is for handling generation of SSL certificates with letsencrypt. 一个用于/blog/并服务于Ghost,第二个.well-known块用于通过letencrypt处理SSL证书的生成。

I'm not an expert at configuring nginx for PHP, but this guide from Digital Ocean and this stackoverflow question covers a lot of the details. 我不是为PHP配置nginx的专家,但是Digital Ocean的本指南以及这个stackoverflow问题涵盖了很多细节。

I think you have a couple of options: 我认为您有两种选择:

  1. Set the index to be index.php 将索引设置为index.php
  2. Add a new location block for / which serves php files /添加新的位置块,以提供php文件
  3. Add a block to handle all php files 添加一个块来处理所有PHP文件

I believe adding a new location block like this, will mean any .php files you have will always be called if the path in the URL matches. 我相信添加这样的新位置块将意味着,如果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;
}

But the value of fastcgi_pass will depend on how you have PHP setup on your system. 但是fastcgi_pass的值将取决于您如何在系统上设置PHP。

With this, going to /index.php should work. 这样,转到/index.php应该可以工作。

Setting index: index.php will mean that / maps to /index.php I'm not sure if that will interfere with Ghost, if it does, you'd need a specific location / {} block instead of the index being set. 设置index: index.php意味着/映射到/index.php我不确定这是否会干扰Ghost,如果确实如此,则需要一个特定的location / {}块而不是设置索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM