landing.php
和我网站的所有其他页面都位于同一目录中。我希望能够同时访问这两个,但是如果我将try_files
语句作为 well 作为index
语句,则在访问索引时会得到404 error
页。
有没有办法在没有冲突的情况下实现这一目标?
这是我的配置文件:
server {
listen 80;
access_log /var/www/mysite.com/logs/access.log;
error_log /var/www/mysite.com/logs/error.log;
root /var/www/mysite.com/public_html/mysite/public/_main;
server_name www.mysite.com mysite.com;
location / {
index landing.php;
try_files $uri $uri.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index landing.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
答案 0 :(得分:2)
我终于弄清楚如何做到这一点。你需要的是两个位置块,如下所示:
location = / {
index landing.php;
}
location / {
try_files $uri $uri.php?$query_string;
}
这样做是为try_files
等任何其他网页使用www.site.com/somepage
;但是,如果URL为www.site.com
,则会获取索引页。
答案 1 :(得分:0)
尝试以下适用于我的配置:
server {
root /path/to/root;
index index.html index.htm;
server_name subdomain.domain.com;
location / {
try_files $uri $uri/ /index.html;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
}
}