I have similar project structures and directories in almost all nodejs apps I'm proxy forwarding via nginx. The structure is as follows:
/var/srv
-/app1
-/public
-/css
-/js
-/img
-/app2
-/public
-/css
-/js
-/img
-/app3
-/public
......
hope you get the idea. For now I've hard coded serving static files code in nginx by providing location and aliasing for each project but I want something like this :
location /$app_var/public/(js or css or img or other static content) {
then aliasing it as
alias /var/srv/$app_var/public/(js or css or img or other static content)
so that it serves static content based on project's directory and I don't have to manually specify each and every project location. please do comment if I haven't explained it better. Thankyou :)
My current config :
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /srv/www/;
index index.html index.htm;
server_name example.com www.example.com;
rewrite ^/(.*) https://nulll.me/$1 permanent;
}
server {
listen 443;
server_name example.com example.com;
root /srv/www/;
index index.html index.htm;
ssl on;
ssl_certificate /home/---------------.crt;
ssl_certificate_key /home/------------.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
location / {
try_files $uri $uri/ =404;
}
location /app1 {
alias /srv/www/watch/;
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
#simillarly more apps
location /app1/public/img {
alias /srv/www/app1/img/;
access_log off;
expires max;
}
# simillarly for /css , /js and for each website.
}