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;
}

相关文章

一、Linux下Nginx的安装 1.去官网 http://nginx.org/download/下载对应的Nginx安装包,推荐使...
一、空格:默认匹配、普通匹配 location / { root /home; } 二、= :精确匹配(表示匹配到 /home/resou...
``` nginx -c 配置文件路径 ``` ``` /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.con...
前言 nginx可所谓是如今最好用的软件级别的负载均衡了。通过nginx的高性能,并发能力强,占用内存下的特...
1.ngnix概念 Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。由俄...
博客园从今天上午就开始报502错误 , 他的原因还不知道 , 暂时先说下我们遇到502的排查情况 最大的可能性...