I have multiple applications setup on one domain, each in its own folder like this:
- example.com/app1
- example.com/app2
- ...
- example.com/appX
My directory tree is like this:
/usr/share/www/
root/
index.html
rc/
index.php <--- roundcube
app1/
public/
css/
js/
index.php
appX/
public/
index.php
One of them is Roundcube webmail others are Laravel apps and root has single html file with links and some info. After a couple of days googling,reading docs, server fault & stack overflow answers i came up with following config which basically works but is very verbose and repetitive and contains hard coded path to laravels index.php script. Is there a more elegant solution to this?
location / {
root /usr/share/nginx/root;
index index.html;
try_files $uri $uri/ =404;
}
location /app1 {
location = /app1/ {
rewrite ^(.*)$ /app1/index.php last;
}
alias /usr/share/nginx/app1/public;
index index.php;
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /app1/index.php last;
}
location ~ /app1/.+\.php$ {
root /usr/share/nginx/app1/public;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/app1/public/index.php;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
# And others like above with adjusted paths
# Setup Roundcube
location ^~ /rc {
root /usr/share/nginx;
index index.php;
try_files $uri $uri/ =404;
location ~ /rc/.+\.php$ {
root /usr/share/nginx/rc;
rewrite /rc/(.*)$ /$1 break;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
location ~ /rc/favicon.ico$ {
root /usr/share/nginx/rc/skins/default/images;
log_not_found off;
access_log off;
expires max;
}
location = /rc/robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/rc/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING|README\.md|composer\.json-dist)$ {
deny all;
}
location ~ ^/rc/(bin|SQL)/ {
deny all;
}
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}