我是 nginx 的新手,我无法确定为什么我的 nginx 配置不能按预期工作。我想做的就是让 nginx 对于每个 Web 根 (/) 请求优先考虑 index.html 而不是 index.php。
这是我的 nginx 配置:
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
multi_accept on;
}
http {
##
# Basic Settings
##
server {
location / {
index index.html index.php;
}
location ~ \.php$ {
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 15;
keepalive_requests 100000;
types_hash_max_size 2048;
client_body_in_file_only clean;
client_body_buffer_size 32K;
client_max_body_size 300M;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
----------------- cut ---------------
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我的错误在哪里?编写这个 nginx 配置的正确方法是什么?
如果您明确请求 /index.html,是否会提供服务?如果没有,您可能需要添加显式root /path/to/root;
给你的server {}
堵塞。还要验证index.html 是否具有正确的权限。
这将有助于故障排除:如果未找到根index.html,它将强制返回 404。如果发生这种情况,至少您可以检查日志以查看它是否正在查找:
location = / {
index index.html;
}
另外,一定要这样做nginx -s reload
更改配置时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)