簡體   English   中英

Nginx別名不起作用

[英]Nginx alias not working

我有一個位置塊,我為其定義了一個不同的別名,並且我希望它的index.php文件成為同一目錄中的服務器。 問題在於Nginx沒有為別名提供索引文件,而是嘗試在根目錄下查找文件(並且它不存在)。

配置:

http {
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 15;

    upstream php {
        server unix:/run/php-fpm.sock;
    }

    server {
        server_name my.domain.com;

        root /var/www;

        location / {
            alias /var/www/site/;
            index index.php;
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass php;
        }

        location ~ /\.ht {
            deny  all;
        }
    }
}

因此,根目錄應該指向根目錄( /var/www )內的site/目錄,但是嘗試提供的文件是/var/www/index.php

2014/05/21 15:41:19 [error] 9591#0: *190 FastCGI sent in stderr: "Unable to open primary script: /var/www/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: my.domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm.sock:", host: "localhost:666"

相反,我希望從/var/www/index.php文件。

Nginx location是唯一的。 離開位置后,nginx會立即忘記所有上下文。 在您這種情況下, try_files最后一項是內部重定向,因此nginx會忽略別名,然后轉到/index.php ,它與location ~ \\.php$匹配,並且root /var/www是從服務器塊繼承的root /var/www

我只是將root指令更改為root /var/www/site ,但是如果您真的想堅持使用這種麻煩的方法,只需將try_files更改為try_files $uri $uri/ /site/index.php?$args

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM