更改固定链接在nginx上出现404个错误

时间:2015-05-21 作者:ninjachicken1

编辑

结果是我试图编辑的树弄错了。htaccess,因为nginx不使用它。我显然需要做的是编辑我的。conf文件。在我读这篇文章之前,我的\\u应用程序。conf如下所示:

upstream backend {
    server unix:/u/apps/my_app/tmp/php.sock;
}

server {

    listen 80 default;
    root /u/apps/my_app/www;
    index index.php;

    access_log /u/apps/my_app/logs/access.log;
    error_log /u/apps/my_app/logs/error.log;

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

    # This location block matches anything ending in .php and sends it to
    # our PHP-FPM socket, defined in the upstream block above.
    location ~ \\.php$ {
        try_files $uri =404;
        fastcgi_pass backend;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /u/apps/my_app/www$fastcgi_script_name;
        include fastcgi_params;
    }

    # This location block is used to view PHP-FPM stats
    location ~ ^/(php_status|php_ping)$ {
        fastcgi_pass backend;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        include fastcgi_params;
        allow 127.0.0.1;
        deny all;
    }

    # This location block is used to view nginx stats
    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}
现在看起来是这样的,但仍然不起作用:

upstream backend {
    server unix:/u/apps/my_app/tmp/php.sock;
}

server {

    listen 80 default;
    root /u/apps/my_app/www;
    index index.php;

    access_log /u/apps/my_app/logs/access.log;
    error_log /u/apps/my_app/logs/error.log;

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

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

    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    location ~* ^.+\\.(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 max;
    }

    # Uncomment one of the lines below for the appropriate caching plugin (if used).
    #include global/wordpress-wp-super-cache.conf;
    #include global/wordpress-w3-total-cache.conf;

    # This location block matches anything ending in .php and sends it to
    # our PHP-FPM socket, defined in the upstream block above.
    location ~ \\.php$ {
        try_files $uri =404;
        fastcgi_pass backend;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /u/apps/my_app/www$fastcgi_script_name;
        include fastcgi_params;
    }

    # This location block is used to view PHP-FPM stats
    location ~ ^/(php_status|php_ping)$ {
        fastcgi_pass backend;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        include fastcgi_params;
        allow 127.0.0.1;
        deny all;
    }

    # This location block is used to view nginx stats
    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}
有人知道我做错了什么吗?

结束编辑,我已将永久链接从默认更改为/%postname%/,现在WordPress管理面板中的链接给了我404个错误,而不是WordPress 404页面,nginx 404页面。查找为什么这是告诉我,这应该是编辑我的。htaccess文件或告诉我WordPress无法重写。htaccess-的。htaccess文件不存在,当我更改永久链接时,WordPress没有给出任何错误。

我试过创建一个空白。我的wordpress文件夹中的htaccess文件,给它666个权限,将用户和组更改为www数据,然后更改永久链接-这不起作用。然后,在更改永久链接之前,我将其更改为:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
当那不起作用时,我改变了RewriteBase/wordpress/ 在再次更改永久链接之前-仍然没有什么。

我也进入了我的网站。conf文件并已更改try_files $uri $uri/ /index.php; 对于以下各项,每次重新启动nginx和php5 fpm;

try_files $uri $uri/ /index.php?$query_string;

try_files $uri $uri/ /index.php?q=$request_uri;

try_files $uri $uri/ /index.php?$args;

我正在用nginx运行一个家庭服务器。你知道这是怎么回事吗?

5 个回复
最合适的回答,由SO网友:s_ha_dum 整理而成

那些是Apache.htaccess 重写规则,但您已经声明您在Nginx服务器上。Nginx不使用.htaccess-与目录级文件一样,它使用.htaccess 文件本身。。您需要编辑服务器配置本身。The Codex has a detail sample:

# WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
    try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\\.(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 max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\\.php(/|$) {
    fastcgi_split_path_info ^(.+?\\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)

    include fastcgi.conf;
    fastcgi_index index.php;
#   fastcgi_intercept_errors on;
    fastcgi_pass php;
}

SO网友:Domi

我正在使用wordpress multisite和自定义永久链接设置:/%category%/%postname%/

/etc/nginx/site available/domain。形态

在服务器上{

location / {
    try_files $uri $uri/ /index.php?q=$uri$args;
}
如果您的根wordpress不是webroot,而是http://domain.com/wordpress/:

location /wordpress/ {
    try_files $uri $uri/ /wordpress/index.php?q=$uri$args;
}
如果您在博客中使用旧的wordpress。目录,添加:位置^ ~/博客。dir{内部;别名/var/www/wordpress/wp-content/blogs.dir;access\\u-log-off;log\\u-not\\u-found-off;expires-max;}

检查nginx配置:sudo nginx-t

重新加载nginx:sudo服务nginx Reload

还可以尝试更改永久链接设置。

SO网友:Angelo Reale

必须将这段代码添加到/sites-available/your-settings-file/sites-enabled/your-settings-file:

server {
[...]

if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}

[...]
}
现在对我有用了。

SO网友:Mendas

我必须设置wordpressś安装目录的根路径:root/var/www/html/wp;

我不喜欢它,因为我在这台机器上安装了更多的应用程序,但创建更多的虚拟主机就足够了。

SO网友:Khandaker Toihidul Islam

第1步。编辑/etc/nginx/site available/example。com公司

location / {
try_files $uri $uri/ /index.php?q=$uri$args;
}
步骤2:登录服务器步骤3。运行此

ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
第4步。测试配置

sudo nginx -t
第5步。重新启动Nginx服务器

sudo systemctl restart nginx
第6步。从wordpress管理仪表板保存永久链接****快乐浏览****

更多详细信息http://toihid.com/wordpress-permalink-in-nginx-server/

结束

相关推荐

当创建一个新的WordPress博客时,WordPress会创建一个新的Linux用户吗?

我想知道WordPress在创建新的WordPress博客时是否创建了新的Linux用户?我是一名NodeJS开发人员,但据我所知,PHP脚本也可以访问整个文件系统。这就是为什么我认为WordPress会为每个博客创建一个新的系统用户。这是真的吗?如果没有,他们如何管理两个WordPress博客之间的访问?