我是新来的nginx,我只是不能find为什么我的nginxconfiguration将无法按预期工作。 我想要做的就是让nginx优先index.php index.php为每个Web根(/)请求。
这是我的nginxconfiguration:
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的configuration?
您应该在虚拟主机文件( /etc/nginx/conf.d/*.conf;
和/etc/nginx/sites-enabled/*;
保留位置和服务器声明,如您从nginx conf中看到的那样)。 /etc/nginx/conf.d/*.conf;
文件/etc/nginx/conf.d/*.conf;
通常符号链接到/etc/nginx/sites-enabled/*;
为了成为“启用”
看到我的博客文章有一个类似于你的设置。
尝试在location {}
块之外移动您的index index.html index.html index.php
文件指令
如果您明确要求/index.html,是否提供服务? 如果没有,你可能想添加一个显式的root /path/to/root;
到您的server {}
块。 另外验证index.html是否具有正确的权限。
这将有助于排除故障:如果没有找到根index.html,它将强制404。 如果发生这种情况,至少你可以检查日志,看看它是在看:
location = / { index index.html; }
此外,请务必在更改配置时执行nginx -s reload
。