Location directive in nginx configuration
5,568
location
is valid only within a server
block, not within the parent http
block. You'll need to put this config inside your server
blocks.
Related videos on Youtube
Author by
ryan
Updated on September 18, 2022Comments
-
ryan over 1 year
I have an nginx server setup to act as a fileserver. I want to set the expires directive on images. This is how a part of my config file looks like.
http { include /etc/nginx/mime.types; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; location ~* \.(ico|jpg|jpeg|png)$ { expires 1y; } include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
I get the following error when I reload config - "Location directive not allowed here".
Can someone tell me what the right syntax for this is?
Thanks in advance.
EDIT : Found the answer myself. Added it in a comment. Closing this.
-
ryan almost 12 yearsYeah after some digging around, I edited the sites-enabled/default file to add the expires header inside a server block. Thanks anyway