![具有一个 PHP 别名/重写的 Ngnix 静态站点](https://linux22.com/image/701361/%E5%85%B7%E6%9C%89%E4%B8%80%E4%B8%AA%20PHP%20%E5%88%AB%E5%90%8D%2F%E9%87%8D%E5%86%99%E7%9A%84%20Ngnix%20%E9%9D%99%E6%80%81%E7%AB%99%E7%82%B9.png)
我有一个静态站点 Angular 站点,我想让路径 /deploy 运行 php 脚本 /var/www/app/deploy/deploy.php。我尝试了重写规则,但没有成功。
正确的做法是什么?
php.conf
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm;
}
虚拟主机配置文件
server {
listen 80;
server_name app.com;
root /var/www/app/;
include /etc/nginx/default.d/php.conf;
location / {
root /var/www/app/frontend/dist;
try_files $uri $uri/ /index.html =404;
rewrite ^/deploy /var/www/app/deploy/deploy.php;
}
}