[英]Cannot get PHP to serve on Nginx — Error 404
我對nginx相當陌生,並認為使用它來提供php很簡單,因為該設置非常普遍,但似乎比我預期的要復雜得多。
這是我的配置
server {
listen 80;
server_name domain.com www.domain.com;
location / {
root /srv/www/domain.com/public_html;
index index.php;
}
# serve static files directly
#location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$
# access_log off;
# expires 30d;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass /var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
如果將“ index.php”替換為“ index.html”文件,nginx會完美地提供html。
我看過一些指南,建議修改從iptables到php-fpm到php.ini,再到fast-cgi到網站可用的任何內容。
我不確定這些教程中有多少試圖確切地做...現在,我只希望我的index.php提供phpinfo()。 解決404錯誤的下一步是什么?
是否有一個明確的指南,介紹了通過nginx服務php可用的各種選項?
Xen上的Debian Wheezy 7.3
試試這個配置:
server {
listen 80;
server_name domain.com www.domain.com;
root /srv/www/domain.com/public_html;
index index.php;
location ~ ^(.+\.php)(/.*)?$ {
fastcgi_pass localhost:9000;
include fastcgi_params;
}
}
(假設您的index.php文件位於/srv/www/domain.com/public_html中)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.