我的 nginx 和 php 已安装并成功运行。在浏览器中输入 URL http://127.0.0.1:8080/ 将显示“欢迎来到 NGINX”页面,当我运行时
php phpinfo.php
在终端上将显示我的 php.ini 中的所有设置。我尝试运行 MY_SERVER_NAME/phpinfo.php 将继续加载而不显示任何内容。当我尝试使用我在 nginx.conf 中设置的 MY_SERVER_NAME 打开我的网站时,它将继续加载而不显示任何内容。
我的web.conf监听80端口,原来的nginx.conf监听8080端口
server{
listen 80;
server_name MY_SERVER_NAME;
root /...../public;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php=404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}
运行 sudo nginx -t 显示语法没问题,测试成功
这应该可行!
server{
listen 80;
listen [::]:80;
server_name SERVER_NAME; # server name of your choice.
root ROOT_DIRECTORY/public; # assumes the index.php is in public folder
index index.php index.html index.htm index-nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php=404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; # assumes PHP listens on the port 9000
}
}
我遇到了类似的问题,希望这个链接对遇到类似问题的人有所帮助 使用 NGINX 安装 Laravel PHP 框架 CentOS 8
对于最近的 Nginx 1.18.0 或更高版本,如果您计划在端口 9000 上运行,那么您的服务器块中需要代理通行证,这应该足够了。
Server {
server_name mysite.com www.mysite.com
listen xxx.xxx.xxx.xxx;
root /path/to/laravel/public/folder;
index index.php index.htm index.html;
..
..
..
#any additional server params
location / {
proxy_pass http://0.0.0.0:9000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
#proxy_set_header Host $host;
}
我猜你不需要 proxy_set_header 参数(如果你的 http 块中指定了)