php - Nginx php文件正在下载而不是执行
问题描述
我已经在 CentOs 7 上配置了 Ngnix 服务器,它正在使用 html 查找,但是当我尝试打开 .php 文件时,它会被下载。我正在使用 PHP7.2。这是我的配置(我使用 123.123.123.123 而不是我的真实 IP):
server {
listen [::]:80 default_server ipv6only=on;
listen 123.123.123.123:80 default_server;
root /var/www/example.com/public_html;
index index.php index.html;
server_name 123.123.123.123;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
因此,当我尝试访问 123.123.123.123/test/index.php 时,我正在下载文件。
我怎么能强制 ngnix 执行 php 文件?
解决方案
你还需要 fastcgi_pass:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
推荐阅读
- visual-studio-code - 是否可以在 VS Code 的窗格之间移动单个打开的文件?
- express - 即使使用 express-validator 的 1 个元素,验证查询参数中数组的所有元素的正确方法是什么?
- python - 使节点不影响图形布局
- c++ - 有没有办法构造一个 constexpr 函数来获取双精度的位表示?
- python - 有什么方法可以知道使用 python selenium 将广告上传到网页的频率?
- javascript - 通过将 POST 请求中的 HTML 表单发送到私有 API 来获取 JWT
- python-3.x - 如何一次从 3 个或更多字典中获取一个随机密钥
- react-native - 右侧的 React Native 导航标题按钮无法正常工作
- reactjs - 将本机函数作为平面列表项中的道具反应
- python - 如何在 Python 3 中从网站/url 获取数据