php - nginx rewrite rules by subdirectory -


i trying achieve following result nginx configuration:

a php app running in subdirectory of server, lets server.com/app/. files in images/ , styles/ (for example) should accessible, php files in api/ should executed, , in other cases nginx should pass whole string after app/ php variable, path.

i have no clue doing here, , can not seem find useful on web, if can chip in, thank you.

i running php5-fpm this:

location /app {     index index.html index.php;      access_log /{...}/access.log;     error_log /{...}/error.log;      location ~ \.php {         try_files $uri = 404;         fastcgi_pass php5-fpm-sock;         fastcgi_index index.php;         fastcgi_param script_filename $document_root$fastcgi_script_name;         include fastcgi_params;     } } 

please ask if need more details.

edit

for found works

location /{path}/ {             index index.php;          access_log /{path}/access.log;         error_log /{path}/error.log;          location ~\.php {             try_files $uri = 404;             fastcgi_pass php5-fpm-sock;             fastcgi_index index.php;             fastcgi_param script_filename $document_root$fastcgi_script_name;             include fastcgi_params;         }             location ~ {              try_files $uri $uri/ /{path}/index.php?path=$uri;         }      }    

however worried might allow unwanted file access. comments?

you can simplify moving try_files directive out of location sub-block config file ends looking like:

location /app {         index index.php;     try_files $uri $uri/ /app/index.php?path=$uri;      access_log /{path}/access.log;     error_log /{path}/error.log;      location ~\.php {         try_files $uri =404;         fastcgi_pass php5-fpm-sock;         fastcgi_index index.php;         fastcgi_param script_filename $document_root$fastcgi_script_name;         include fastcgi_params;     }  } 

the key thing try_files directive - nginx try each location in order specified. $uri looks file matching exact path specified (so /api/random.php loads correctly because it's file), $uri/ looks folder matching path, , attempts load index folder, , /app/index.php?path=$uri loads page /app/index.php. picked location ~\.php block , passed php-fpm.

the main thing i'd concerned access , error.log files publicly accessible virtue of being stored in web directory. if possible, shift them somewhere else (like /var/log maybe?)


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -