大网数据广告活动
服务器运维问答

Nginx Subdirectory - Location Path Added to Root

· 52CE 我爱测

Working on accessing a wordpress install in a subdirectory off my main webroot. My main website is stored in /var/www/example.com/htdocs My wordpress install is stored in /var/www/wordpress.example.com/wordpress I want to be able…

问题原文

原帖链接 · Dan Hanly · CC BY-SA 3.0

Working on accessing a wordpress install in a subdirectory off my main webroot.

My main website is stored in /var/www/example.com/htdocs
My wordpress install is stored in /var/www/wordpress.example.com/wordpress

I want to be able to access my wordpress install from example.com/blog

server {
    ...
    root /var/www/example.com/htdocs;
    ...

    location ^~ /blog {
        root /var/www/wordpress.example.com/wordpress;
    }
}

However, I'm getting a 404 where /blog is added to the root also (which isn't desired).

"/var/www/wordpress.example.com/wordpress/blog/index.php" is not found

Notice how the root shows both /wordpress and /blog. My desire would be for it only to show /wordpress. I want it to be accessible from /blog, but /blog should not be part of the root, because it doesn't exist.

Could you help me resolve this?

已采纳解答

原帖链接 · Ilham Sulaksono · CC BY-SA 3.0

The answer that @Drifter104 is correct, i just want to add an explanation. You are wrong using the directive, you should be using alias directive instead of root. If you are using root, the requested_uri(location value) will be added to file path. In your case, if the request_uri(location value) /blog, nginx will search the file path in /var/www/wordpress.example.com/wordpress+/blog. But if you using alias, the file path that nginx will search is not based on location value. Here is the nginx documentation http://nginx.org/en/docs/http/ngx_http_core_module.html#alias.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。