当wordpress不在主目录中时,在nginx上重写wordpress url [英] Wordpress url rewrite on nginx when wordpress is not in the main directory

查看:136
本文介绍了当wordpress不在主目录中时,在nginx上重写wordpress url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我总是很难让Wordpress在Nginx上运行.

For some reason I always have trouble getting Wordpress to work on nginx.

我在文件夹"site"(位于public_html内)中安装了Wordpress. 这是我的nginx配置:

I have my Wordpress installation in the folder "site" (inside public_html). This is my nginx configuration:

server {
    server_name www.wouterds.be wouterds.be;
    access_log /srv/www/www.wouterds.be/logs/access.log;
    error_log /srv/www/www.wouterds.be/logs/error.log;

    location / {
        root /srv/www/www.wouterds.be/public_html;
        index index.php index.html index.htm;
        try_files $uri $uri/ /site/index.php?$args;
        autoindex on;
    }

   location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/www.wouterds.be/public_html$fastcgi_script_name;
    }
}

当我访问我的网站 http://wouterds.be/时,我只会得到目录索引. 当我访问 http://wouterds.be/blog/时,页面显示正确,一切正常. 但是我不知道如何在基本网址上使用它.

When I visit my website http://wouterds.be/ I get just the directory index. When I visit http://wouterds.be/blog/ I get the right page and everything is working. But I have no idea how to get it work on the base url.

有人可以帮助我一点吗?我当然不是nginx专家,经过4个小时的Google-ing测试后,我决定在这里尝试一下.

Anyone who can help me out a bit? I'm certainly not an nginx expert and after 4 hours Google-ing I decided to give it a try here.

推荐答案

您也可以尝试(不在位置限制中):

You can also try (not in a location block):

rewrite /wp-admin$ $scheme://$host$uri/ last;
rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;

/wp/替换为/site/或任何您的wordpress目录.

Exchange /wp/ for /site/ or whatever your wordpress directory is.

来源:

https://wordpress.stackexchange.com/questions/138648 /nginx-rules-for-subdomain-multisite-install-bedrock

这篇关于当wordpress不在主目录中时,在nginx上重写wordpress url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆