I want every request for http://localhost/static/
to be directed to /usr/share/nginx/static
.
For example, it the user requests http://localhost/static/style/style.css
, I want the server to reply with the content of /usr/share/nginx/static/style/style.css
.
This is my code (which does not work):
server {
server_name http://localhost/;
rewrite ^/static/(.*) /usr/share/nginx/$1 permanent;
}
And this is the main config file:
worker_processes 1;
events {
worker_connections 200;
}
http {
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Include Other Configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Update: I have a file named mysite.conf like this which does not rewrite the urls as i mentioned in the question.
location /static {
root /usr/share/nginx/static;
}