Answer the question
In order to leave comments, you need to log in
How to use rewrite in Nginx to return the result of test.js.php execution instead of test.js?
Task: when requesting site.ru/test.js , the completed /php/test.js.php with content-type application/x-javascript should be returned .
In Apache it worked like this:
RewriteEngine on
RewriteRule ^test.js php/test.js.php [L]
location / {
...
rewrite ^/test.js /php/test.js.php break;
}
location ~ \.php$ {
...
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
...
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
rewrite ^/test.js /php/test.js.php break;
}
Answer the question
In order to leave comments, you need to log in
This may sound stupid (I've only been using nginx for a couple of weeks), but wouldn't it be easier/better to make a separate location for this file instead of "rewrite ^/test.js /php/test.js.php break;"?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question