如何配置 Nginx 以执行 PHP [英] How to Configure Nginx to Execute PHP
问题描述
这是nginx.conf
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /Users/*name*/PHPSITE/standard;
index index.html index.htm;
try_files $uri $uri/ /index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /Users/*name*/PHPSITE/standard;
}
location ~ \.php$ {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
fastcgi_param SCRIPT_FILENAME /Users/*name*/PHPSITE/standard$fastcgi_script_name;
}
}
但是当我在 127.0.0.1:9000 上运行时它不起作用.在本地主机上,它显示 403 Forbidden.如您所见,我删除了注释行.
But when I'm running on 127.0.0.1:9000 it doesn't work. On localhost it shows 403 Forbidden. As you can see, I deleted commented lines.
推荐答案
你应该总是使用 $document_root
而不是在任何地方提供根路径
You should always use $document_root
instead providing root path everywhere
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
并检查您的 php-fpm 进程是否正在运行,例如您是否正在使用 systemctl run
And check if your php-fpm process is running, for example if you are using systemctl run
systemctl status php-fpm
systemctl start php-fpm
还要检查您是否使用相同的 fast_cgi 路径,它应该在 php-fpm 文件的 www.conf 中匹配(可以在这里/etc/php-fpm.d/www.conf)
also check if you are using same fast_cgi path, it should match in www.conf of php-fpm file ( could be here /etc/php-fpm.d/www.conf)
listen = 127.0.0.1:9000
和你的站点配置 nginx.conf 文件
and your site config nginx.conf file
fastcgi_pass 127.0.0.1:9000;
更新文件后重启 Nginx/php-fpm 服务.
after updating files restart your Nginx/php-fpm services.
然后在浏览器中访问 http://localhost(如您在上面设置的 server_name),而不是 127.0.0.1:9000.
and than visit http://localhost (as you set server_name above) in your browser , not 127.0.0.1:9000.
这篇关于如何配置 Nginx 以执行 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!