0

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.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • You have asked to load files from, e.g. `/var/www/html/thedomain/cms/cms/mysite.css`. Did you really mean to use `cms` twice in the path? – Michael Hampton Mar 26 '19 at 17:48
  • Do your configuration files really have the space before `;` in your `root` directive lines? That might also cause issues. Also, please show nginx `error.log` entries for the files in your question. – Tero Kilkanen Mar 26 '19 at 19:44
  • You should know that location with regexp stops at first match so you must put specific locations before general ones. In you case you should swap second and third locations – Alexey Ten Mar 26 '19 at 19:46

0 Answers0