所有子页面的 NGINX wordpress 404

NGINX wordpress 404 for all subpages

我有两个问题,但我认为它们是相关的。 /wp-admin/blog return 404 等子目录,因此,永久链接在 /blog/category1/page.php

之后不起作用

我的设置:

我有一个服务器 192.168.1.4 运行 nginx。在另一台服务器上,192.168.1.1 我有一个使用虚拟主机的 apache 网络服务器,它托管我的 wordpress 网站。在没有 nginx 的情况下,设置工作正常,但是当我打开 nginx 时,我遇到了一些问题。

Nginx 无法使用永久链接。我使用了默认值,所以现在它像:http://www.mywebsite.co.uk/?page_id=90 可以正常工作(只要它不在子目录中)。

子目录(不是根目录)中的所有内容都损坏了。包括管理页面 http://www.mywebsite.co.uk/wp-admin, or (before turning off permalinks) http://www.mywebsite.co.uk/blog。他们都去404,具体来说:404 Not Found nginx/1.4.6 (Ubuntu)

这是我的配置:

server {
   server_name mywebsite.co.uk www.mywebsite.co.uk;
   location / {
        index index.php;
        proxy_pass http://192.168.1.1$request_uri;

        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        try_files $uri $uri/ =404;
        #try_files $uri $uri/ /index.php?$args; #not working, error: rewrute or internal redirection cycle while interally redirecting to index.php
   }
}

作为参考,这是我的永久链接:/blog/%category%/%postname%/

更新

尝试将此添加到我的配置中:

server {
    ... config above ...
   location /wp-admin/ {
       index index.php
       try_files $uri $uri/ /wp-admin/index.php?$args;
       proxy_pass http://192.168.1.1$request_uri; 
       proxy_set_header Host $host; 
    }
}

这会在日志中返回一个错误:

rewrite or internal redirection cycle while internally redirecting to "/wp-admin/index.php", client: xxxxx, server: mydomain.co.uk`

您有一些工作配置。 nginx 在您的配置中的目的是反向代理到 Apache 服务器。 indextry_files 在这种情况下是不合适的。尝试:

server {
    server_name mywebsite.co.uk www.mywebsite.co.uk;
    location / {
        proxy_pass http://192.168.1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
   }
}

为什么你不想在没有 apache 的情况下尝试 wordpress? 工作配置将是这样的:

server {
    listen 80;    
    server_name site.com;
    root /home/www/site.com;

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

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # SECURITY : Deny all attempts to access PHP Files in the uploads directory
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }

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

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

    location = /robots.txt {allow all; log_not_found off; access_log off; }

    error_page 404 /404.html;

    location ~ /\. { deny all; }

    location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; 
        log_not_found off; 
        expires 30d;
    }
}

也许你可以在这里得到答案Ultimate NGINX configuration for Wordpress » www.geekytuts.net

我发现我的问题是 mod_rewrite 没有启用。我不得不 运行 使用 apache

在服务器上重写 a2enmod