Nginx - 重写/到子文件夹

时间:2012-07-09 00:21:28

标签: php nginx

我有一个站点,它位于文档根目录的根级别。我将它移动到新文档根目录中的子文件夹I.所有链接都是绝对的(/assets/styles.css,/folder/file.php)。我的子文件夹位于example.com/sub/。有什么方法可以让Nginx重写/资产到example.com/sub/assets吗?

1 个答案:

答案 0 :(得分:0)

你的nginx.conf

中应该有这样的东西
    location /assets {
        root   /var/www/example.com/documentroot/;
        ...
    }

告诉NginX从该目录中获取“资产”。除非我弄错了,你应该只需编辑“/var/www/example.com/documentroot/sub /".

中的根文件夹。

或者,你有一个完整的根源:

    location / {
        root   /var/www/example.com/documentroot/;
        index index.php;
        ...
    }

再次,您只需将“sub /”添加到“documentroot /".

最后,如果您只想移动“资产”,请在nginx.conf中编辑或添加“location / assets”配置节。

相关问题