1

I have a static site Angular site and I want to have the path /deploy run a php the php script /var/www/app/deploy/deploy.php. I have tried a rewrite rule and having no luck.

What is the proper way to do this?

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;
    }
}
Raymond
  • 11
  • 1

1 Answers1

2

Your rewrite statement needs a URI as the target and not the pathname. You should use:

rewrite ^/deploy /deploy/deploy.php last;

See this document for details.

Rather than use a rewrite statement in the location / block, you might consider the slightly cleaner option of moving it into an exact match location block:

location = /deploy {
    rewrite ^ /deploy/deploy.php last;
}

See this document for details.

Richard Smith
  • 11,859
  • 2
  • 18
  • 26