【问题标题】:Nginx: use a directory as root /Nginx:使用一个目录作为root /
【发布时间】:2014-11-20 16:30:08
【问题描述】:

正如标题所说,我想在我的 Nginx 服务器上使用一个目录作为我的根目录。 我有一个类似这样的目录树:

/www
folder A
Folder B
Folder C

我想配置 Nginx,以便根 / 应该是 i 文件夹 A(example.com/ 将在文件夹 A 中)。但是,如果用户键入 example.com/FolderB/,则该用户应该跳上一个目录并到达文件夹 B。文件夹 C 也是如此。

我尝试使用位置、别名和 root 来更改用户所在的位置,但无法正常工作。

【问题讨论】:

    标签: nginx directory config root


    【解决方案1】:

    将站点的根目录设置为 /www。 然后在根位置添加一个try_files:

    root /www;
    location / {
        try_files $uri $uri/ /A/$uri /A/$uri/ =404;
    }
    

    【讨论】:

    • 没有让它工作。它给了我一个 403。它试图在 /www 文件夹中打开 index.php
    • 也许您没有添加index index.html index.php;?还是文件夹的权限不对?
    • 是的,这是我的第一个想法。但我会在这里发布我的配置: server{ listen 80; server_name example.com;根/www;索引 index.html 索引.php; client_max_body_size 10m; # 从 url 位置删除 .php / { if (!-e $request_filename){ rewrite ^(.*)$ /$1.php; } # folderA 作为根 try_files $uri $uri/ /folderA/$uri /folderA/$uri/ =404; } 位置 ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php;包括 fastcgi_params; } }
    猜你喜欢
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 2018-11-23
    • 2018-02-24
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    相关资源
    最近更新 更多