【发布时间】:2021-02-27 06:20:18
【问题描述】:
我正在 AWS Linux 2 上设置 Nginx + PHP Web 服务器。它是全新安装的,安装了 nginx 和 PHP7.4。下面是nginx中的虚拟主机配置文件。
我需要将所有流量重定向到 index.php,因为它是一个单页应用程序。
当我转到 www.xxx.com/index.php 时,PHP 页面呈现正常(因此 PHP 肯定在运行)。
当我转到www.xxx.com/login/时,浏览器提示下载index.php文件而不是执行它。
有人可以帮忙吗? (我已尝试清除浏览器缓存)。
/etc/nginx/conf.d/myapp.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/vhosts/app.userback.io/frontend/;
index index.php index.html index.htm;
server_name www.myapp.com;
location / {
try_files $uri $uri/ /index.php =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
}
【问题讨论】:
标签: php linux nginx amazon-ec2 amazon-linux-2