我有一个静态网站Angular网站,我想要path/部署运行一个PHP的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; }
vhost.conf
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; } }
您的rewrite语句需要一个URI作为目标,而不是path名。 你应该使用:
rewrite ^/deploy /deploy/deploy.php last;
详情请参阅此文件 。
而不是在location /块中使用rewrite语句,您可以考虑将其移动到精确匹配位置块的稍微更简洁的选项:
location = /deploy { rewrite ^ /deploy/deploy.php last; }
详情请参阅此文件 。