nginx更改specyfic url的根文件夹

我有一个如下配置文件

    server {

        listen       80;
        server_name  localhost;

        #charset utf-8;
        root   html/laravel/public;
        index  index.html index.PHP;

        #browse folders if no index file
        autoindex on;

        # enforce NO www
        if ($host ~* ^www\.(.*))
        {
            set $host_without_www $1;
            rewrite ^/(.*)$$scheme://$host_without_www/$1 permanent;
        }

        # serve static files directly
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)${
            access_log off;
            #expires max;
        }

        # removes trailing slashes (prevents SEO duplicate content issues)
        if (!-d $request_filename)
        {
            rewrite ^/(.+)/$/$1 permanent;
        }

        # canonicalize codeigniter url end points
        # if your default controller is something other than "welcome" you should change the following
        # if ($request_uri ~* ^(/lobby(/index)?|/index(.PHP)?)/?$)
        # {
        #     rewrite ^(.*)$/ permanent;
        # }

        # removes trailing "index" from all controllers
        if ($request_uri ~* index/?$)
        {
            rewrite ^/(.*)/index/?$/$1 permanent;
        }

        # unless the request is for a valid file (image,js,css,etc.),send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^/(.*)$/index.PHP?/$1 last;
            break;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location /backend/ {
            root /html/frontend;
        }

        location ~ \.PHP${
            include fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.PHP;
            include fastcgi_params;
        }

        location ~ /\.ht {
            deny  all;
        }

        # catch all
        # error_page 404 /index.PHP;

        # location ~ \.PHP${
        # try_files $uri =404;
        #         fastcgi_pass  unix:/tmp/PHP.socket;
        #         fastcgi_index index.PHP;
        #         #include fastcgi_params;
        #         include /home/tamer/code/Nginx/fastcgi_params;
        # }
        # access_log /home/tamer/code/laravel/storage/logs.access.log;
        # error_log  /home/tamer/code/laravel/storage/logs.error.log;
    }

我必须使用$host / backend /将根文件夹更改为html / backend以获取任何URL.加载页面的所有规则必须相同,只有根文件夹必须更改.

我怎样才能做到这一点?

最佳答案
将127.0.0.1添加到server_name以便能够使用您在注释127.0.0.1中提供的链接

server_name localhost 127.0.0.1;

你还需要有一个带有root的后端位置.

location /backend/ {
    root /html/backend;
}

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...