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

Nginx can't map URL to directory outside of the root

· 52CE 我爱测

I have a PHP site that's running fine. Now I need to add URL /adminer/ that is mapped to a directory outside of the root and there I have an index.php file that needs to be executed. I have following config (Debian 9.7): server {…

问题原文

原帖链接 · Bruce · CC BY-SA 4.0

I have a PHP site that's running fine. Now I need to add URL /adminer/ that is mapped to a directory outside of the root and there I have an index.php file that needs to be executed. I have following config (Debian 9.7):

server {
    listen 80;

    root /home/usr/www/xxx.xxx/web/app/www;
    index index.php;

    server_name xxx.xxx;

    location /adminer {
        root /home/usr/www/xxx.xxx/web/adminer;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/xxx.xxx.php7.0-fpm.socket;
    }
}

When I open http://xxx.xxx/adminer/ I always get 404. I am trying for more than a hour different configs but can't find a working way. Thanks

已采纳解答

原帖链接 · Bruce · CC BY-SA 4.0

Based on Richar Smith's comment, this is a working config:

server {
    listen 80;

    root /home/usr/www/xxx.xxx/web/app/www;
    index index.php;

    server_name xxx.xxx;

    location /adminer {
        root /home/usr/www/xxx.xxx/web;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/xxx.xxx.php7.0-fpm.socket;
        }
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/xxx.xxx.php7.0-fpm.socket;
    }
}

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

资料来源与适用范围

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

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

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