A regular expression in nginx location?

Good evening, already 2 3 days struggling with the problem
location ~* ^/.+\.(php)$ { — a regular expression in the nginx configuration file, which tells us that if the requested *file.php, this location marks.


Before me stands a challenge: make location excludes php. That is, if the request is NOT php, then location is processed.


Option ~* .+(!?php)$ from nginx does not pass (he stubbornly continues to request a static with Apache, apparently there are special regexp..). ~* in nginx means case-insensitive.


There is an option ~* ^(.+?)[^/.php]$, but it is not fulfills the human references of the form/link2/link3, but fulfills/link2/link3/ (it ends with the slash). And you have to override the other location files .h, .p, .ph, .hp, .*ph and .*php.


Please help to create correct location and send my nginx on the right path.


If the option all in 1 is impossible, what are the 2 location to create the specifics of nginx?


nginx with offsite, downloaded the sources, configured to suit the needs and make && make install.
submodsubstitutions4nginx mod of this topic.

nginx -V
nginx version: nginx/0.8.54<br>
built by gcc 4.4.5 (Debian 4.4.5-8)<br>
TLS SNI support enabled<br>
configure arguments: --with-http_ssl_module --with-pcre --with-http_dav_module --with-http_realip_module --with-http_stub_status_module --with-http_sub_module --with-http_addition_module --add-module=/usr/udata/nginx-0.8.54/submod
October 10th 19 at 13:27
4 answers
October 10th 19 at 13:29
If I understand correctly what you want, here: to give everything that is not php directly.
server {
...
 index index.php;
...
 location ~ ^.*\.php
{
...
}
 root /path/to/your/static/files/;
}
In your case index.php.jpg cheating on the server and the query is dynamic (anyname.php*).
Also, if the request is index.php without any parameters, but the server gives the php file.

With regards to the config: location ~ ^.*\.php {nginx to connect to Apache as a proxy}
root /path/to/your/static/files/ — here the path to the folder where it is, and statics and dynamics. They have to be together (as user from ftp server uploaded). - Isabell_Farrell62 commented on October 10th 19 at 13:32
1) location ~ ^.*\.php$
2) do not understand. but it is an option for the dump of statics and dynamics. - jaylin52 commented on October 10th 19 at 13:35
Now everything was fine, but the links /joomla/index.php/getting-started are processed by nginx. (in the log failed (20: Not a directory)) (or such /2011/04/17 and /2011/04/17/)

Here is the piece of config
...
index index.php;<br> location ~ ^.*\.php$ {<br> proxy_pass <a href="http://localhost">localhost</a>:8184;<br> include a param/zone6rs;<br> proxy_set_header Host $Host;<br> proxy_set_header X-Real-IP $remote_addr;<br> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br> proxy_buffer_size 512k;<br> proxy_buffers 32 512k;<br> proxy_busy_buffers_size 512k;<br> proxy_temp_file_write_size 512k;<br> #include param/prx_c20_s20_r30;<br> proxy_connect_timeout 120;<br> proxy_send_timeout 100;<br> proxy_read_timeout 100;<br> # index index.php;<br> proxy_cache off;<br> <br / > }<br> location ~ ^ {<br> root /usr/webusers/wwwnikitas/www/;<br> include a param/zone12rs;<br> }<br>
If instead of location ~ ^ { leave just a root — the same effect. - Isabell_Farrell62 commented on October 10th 19 at 13:38
 location / {
 if ( !-e $request_filename ) {
 rewrite ^(.*)$ /index.php last;
}
}

redirect all requests for non-existent files\folder on index.php - maureen.Greenholt commented on October 10th 19 at 13:41
October 10th 19 at 13:31
Solution 1. I certainly understand that in php like to blame the source code and statics in one pile, but I suggest just to move all statics into a single folder /static/ 'll be using nginx and safely give all URLs starting with /static/ as statics, and the rest in php.
Solution 2. In nginx locarini with regexp are sequential, so you can write:
location ~* \.php$ {
...
}
location ~ ^ {
root /project/;
}
All that will not pass by the first condition will go on.
In your case, not processed for links of the form /link2/link3 and /link2/link3/ - Isabell_Farrell62 commented on October 10th 19 at 13:34
October 10th 19 at 13:33
If the task is send to php on the backend, and static to give the disk, then will help try_files:

location / {<br> try_files $uri $uri/ @php;<br> }<br> <br / > location @php {<br> ...<br> }
in the case of config

location / {<br> try_files $uri $uri/ @php;<br> }<br> <br / > location @php {<br> proxy_pass to apache;<br> }

files are read by Apache and nginx gives them.

Option

root path to the project;<br> location / {<br> try_files $uri $uri/ @php;<br> }<br> <br / > location @php {<br> proxy_pass to apache;<br> }
Apache handles all the 404 and all the dynamics, the statics also regularly issued nginx.
But links like /mysite or /mysite/ give a 403 from nginx.
directory index of "/full path to the folder/" is forbidden

In any case, thanks for the idea. Try to combine all the options. - Isabell_Farrell62 commented on October 10th 19 at 13:36
added index index.php; in the server{ links earned. leave as an option + to try to finalize.
Thank you. - jaylin52 commented on October 10th 19 at 13:39
and another addition — direct requests in php processed by Apache only if location ~ \.php$ {, otherwise nginx will send the file. - Isabell_Farrell62 commented on October 10th 19 at 13:42
October 10th 19 at 13:35

location / {
 try_files $uri $uri/ /index.php?q=$request_uri;
}

wiki.nginx.org/Joomla
All requests for static go directly to apache (if same as the instructions here to implement). - Isabell_Farrell62 commented on October 10th 19 at 13:38

Find more questions by tags FrontendRegular expressionsBackendNginx