I am trying to setup an Nginx server (Centos 7) as front-end proxy server to a live server running Apache. (When its working, I will make the proxy server the live server).
I have basically got it working as-is, but I want to try and speed it up by getting Nginx to serve static files from two local folders. I have created a copy of the /root and /cms folders (the cms is an alias folder on the Apache server).
Here is my non-working config, (without the server section, for simplicity)
location / {
proxy_pass https://www.thedomain.com:443;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ~* .(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
root /var/www/html/thedomain/www/ ;
}
location ~* /cms/.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
root /var/www/html/thedomain/cms/ ;
}
I tried different approaches to the location blocks, but nothing seems to work.
location ~* .(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
root /var/www/html/thedomain/www/ ;
try_files $uri @cms ;
}
location @cms {
root /var/www/html/thedomain/cms/ ;
}
I don't know if this clear but what I want to do is serve js,css,jpg etc from "/var/www/html/thedomain/www" except for those static files in the /cms/ folder such as "/cms/mysite.css". Serving the CMS folder static content, isn't that important as users in the cms folder are the site admins.
At the moment Nginx is returning a 404 for any static files located in the /cms folder.
I am fairly new to Nginx so any help appreciated.