trouble with static content (Revised)

deeztek nginx-forum at forum.nginx.org
Sun Nov 7 12:01:58 UTC 2021


I posted about this issue a few days ago, however I fear that I needlessly
complicated the question and some of the problems that I encountered were
due to browser cache. So, here I go again:

With the following configuration, I get static content on the /admin
location but NOT the / location:

==== STARTS HERE ====

server {
        #LISTEN CONFIG
        listen 443 ssl;
        server_name host.domain.tld
        #HSTS CONFIG UNCOMMENT BELOW TO ENABLE
        add_header Strict-Transport-Security "max-age=31536000; preload";
        keepalive_timeout   70;
        #LOGS CONFIG
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log warn;
        #SSL LETS ENCRYPT CERTIFICATE CONFIG
        ssl_certificate    
/etc/letsencrypt/live/smtp-dev.deeztek.com/fullchain.pem;
        ssl_certificate_key
/etc/letsencrypt/live/smtp-dev.deeztek.com/privkey.pem;
        # Turn on OCSP stapling as recommended at
        # https://community.letsencrypt.org/t/integration-guide/13123
        # requires nginx version >= 1.3.7
        #ssl_stapling on;
        #ssl_stapling_verify on;
        # maintain the .well-known directory alias for Lets Encrypt
Certificate Renewals
        location /.well-known {
        root /var/www/html/;
        }
        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
        #ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        proxy_max_temp_file_size 5120m;
        client_max_body_size 5120m;
        include /etc/nginx/snippets/authelia.conf; # Authelia auth endpoint
        #root /var/www/html;
        index index.cfm;


location / {
        set $upstream_authelia http://127.0.0.1:9091;
        proxy_pass $upstream_authelia;
        client_body_buffer_size 128k;

        #Timeout if the real server is dead
        proxy_next_upstream error timeout invalid_header http_500 http_502  
  http_503;

        # Advanced Proxy Config
        send_timeout 5m;
        proxy_read_timeout 360;
        proxy_send_timeout 360;
        proxy_connect_timeout 360;

        # Basic Proxy Config
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 64 256k;

        # If behind reverse proxy, forwards the correct IP
        set_real_ip_from 10.0.0.0/8;
        set_real_ip_from 172.0.0.0/8;
        set_real_ip_from 192.168.0.0/16;
        set_real_ip_from fc00::/7;
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;
    }

location ~* .(?:ico|css|js|gif|jpe?g|png|woff2|map)$ {
expires max;

}


location /admin/ {

        proxy_pass http://localhost:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        root /var/www/html/;
        include /etc/nginx/snippets/auth.conf; # Activates Authelia for
specified route/location, please ensure you have setup the domain in your
configuration.yml
}

==== ENDS HERE ====

However, if I remove the following from the configuration above, I get
static content from the / location but NOT the /admin location:

location ~* .(?:ico|css|js|gif|jpe?g|png|woff2|map)$ {
expires max;

}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,292760,292760#msg-292760



More information about the nginx mailing list