NGINX try_files + alias directives

后端 未结 3 1297
后悔当初
后悔当初 2020-12-23 09:42

I\'m trying to serve request to /blog subdirectory of a site with the php code, located in a folder outside document root directory. Here\'s my host config:

         


        
3条回答
  •  半阙折子戏
    2020-12-23 10:03

    There is another workaround which gives more flexibility. It consists of a proxy_pass directive which points on 127.0.0.1 and another server block.

    In your case it should looks like this:

    upstream blog.fake {
        server 127.0.0.1;
    }
    server {
        server_name local.test.ru;
        root /home/alex/www/test2;
        index index.html;
    
        location /blog {
            proxy_pass http://blog.fake/;
        }
    }
    server {
        server_name blog.fake;
        root /home/alex/www/test1;
    
        location / {
            try_files $uri $uri/ /index.php$is_args$args;
        }
    
        location ~ \.php(/|$) {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param HTTPS off;
        }
    }
    

提交回复
热议问题