Answer the question
In order to leave comments, you need to log in
How to configure location and rewrite in nginx?
2nd day fiddling with nginx, fastcgi, please help.
The project is in /home/test/www/project/
The folder structure is as follows:
in /project/
*.php //php scripts
css, images, videos // folders in them content
I go to the browser subdomain.domain.com/project/main .php (or index.php should be transferred to main.php). Let's say I watch the video subdomain.domain.com/project/main.php?v=555, everything is fine and works well.
The following is required:
Hitting a link like subdomain.domain.com/project/555 so that 555 is passed to index.php as a get parameter. That is, there was an analogue of the request subdomain.domain.com/project/main.php?v=555, but without a redirect, that is, so that subdomain.domain.com/project/555 remains in the browser line.
There are no locations relative to the project folder in nginx default.
I add the first one:
location /project/ {
rewrite ^/project/(.*)$ /project/main.php?i=$1 last;
}
location /project {
index index.php;
if (!-e $request_filename) {
rewrite ^/([^?]*)(?:\?(.*))? /project/main.php?i=$1 last;
}
if ($uri ~* "\.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$") {
expires max;
break;
}
}
Answer the question
In order to leave comments, you need to log in
final config with which everything worked
location /project/ {
root /home/www;
index index.php;
try_files $uri @php;
}
location /project/content/ {
alias /home/www/project/content/;
valid_referers blocked *.mysite.com;
if ($invalid_referer) {
return 403;
}
try_files $uri @php;
}
location @php {
rewrite ^/([^?]*)(?:\?(.*))? /project/main.php?i=$1 last;
}
Thanks everyone!
got it with:
location /project/ {
alias /home/test/www/project/;
index main.php;
try_files $uri @php;
}
location @php {
rewrite ^/project/(.*)$ /project/main.php?i=$1 last;
}
location /project/content/ {
valid_referers none blocked mysite.com *.mysite.com;
if ($invalid_referer) {
return 403;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question