V
V
Vitaly Frolov2017-10-11 15:50:57
Nginx
Vitaly Frolov, 2017-10-11 15:50:57

How to add this code correctly to nginx.conf?

I have a file like this

user  apache;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
    use epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;


proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;

client_max_body_size 100m;

gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 10;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
gzip_vary on;
gzip_proxied any; 
gzip_disable msie6;


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/vhosts/*/*.conf;
    server {
        server_name localhost;
 disable_symlinks if_not_owner;
        listen 80;
  include /etc/nginx/vhosts-includes/*.conf;
  location @fallback {
    error_log /dev/null crit;
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect http://127.0.0.1:8080 /;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    access_log off ;
  }
    }
}

I need to add this:
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
root /var/www/clients/data/www/site.ru;
access_log /var/www/httpd-logs/site.ru.access.log ;
access_log /var/www/nginx-logs/clients isp;
expires 7d;
}
how to do it correctly? Where to stick this code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2017-10-11
@HeadOnFire

In server{...}.
From documentation:

Syntax: location [= | ~ | ~* | ^~ ] uri { ... }
location @name { ... }
Default: -
nginx.org/en/docs/http/ngx_http_core_module.html#l...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question