N
N
nikitasius2011-04-17 23:46:14
Nginx
nikitasius, 2011-04-17 23:46:14

Regular expression in location nginx?

Good evening, I've been struggling with the problem for 23 days now
location ~* ^/.+\.(php)$ {- a regular expression from the nginx config, which tells us that if the requested file is * .php, then this location is executed.
My task is to make location exclusive of php. That is, if the request is NOT php, then the location is processed.
The option ~* .+(!?php)$does not work for nginx (it stubbornly continues to request statics from Apache, apparently regexp is special there ..). ~*- in nginx means case insensitive.
There is an option ~* ^(.+?)[^/.php]$, but it does not work out human links of the form /link2/link3, but it does /link2/link3/(at the end there is a slash). And you have to redefine the files in other locations .h, .p, .ph, .hp,.*phand .*php.
Please help me create the correct location and point my nginx to the right path. If the all-in-1
option is not implemented, then what 2 locations should be created, given the specifics of nginx? nginx from offsite, sources downloaded, configured for needed and . — mod from this topic. nginx -V
make && make install
submodsubstitutions4nginx

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

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan, 2011-04-18
@iSage

If I understand correctly what you want, then here it is: give everything that is not php directly.

server {
    ...
    index index.php;
    ...
    location ~ ^.*\.php
    {
        ...
    }
    root /path/to/your/static/files/;
}

V
Vlad Frolov, 2011-04-18
@frol

Decision 1. Of course, I understand that php likes to dump sources and statics into one heap, but I advise you to just put all the statics in one folder /static/ and you will calmly send all urls starting with /static/ as static through nginx, and the rest - in php.
Solution 2: In nginx, regexp locales are executed sequentially, so you can write:
location ~* \.php$ {

}
location ~ ^ {
root /project/;
}
Everything that does not pass according to the first condition will go further.

N
niakrisn, 2011-04-20
@niakrisn

If the task is to send php to the backend, and give the statics from the disk, then try_files will help:
location / {
try_files $uri $uri/ @php;
}
location @php {
...
}

I
Ivan, 2011-04-18
@iSage


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

wiki.nginx.org/Joomla

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question