I have tried the offered solutions:
Nginx rewrite triggers download
nginx rewrite to php file - File is being downloaded
but to no avail.
when I click on the link to /contact
it just downloads my redirected file.
my config:
rewrite ^/test$ /index.php last;
rewrite ^/contact$ /index.php last;
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
index index.php index.html index.htm;
}
when I visit /test
it redirects successfully, but when I try and access /contact
it fails. Accessing php directly works as expected.
I have also tried with the rewrites in the location /
block, but I get the same error.
edit
I have taken out all my redirect rules, and it still downloads my index file.
nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
passenger_root /usr/lib/passenger/;
passenger_ruby /usr/local/rvm/wrappers/ruby-head/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server_names_hash_bucket_size 64;
#gzip on;
include /opt/nginx/conf/enabled/*.conf;
}
/opt/nging/conf/enabled/root.conf
server {
listen 80;
server_name example.com;
root /srv/http/public;
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}