Q
Q
qudri2019-04-13 11:32:02
Nginx
qudri, 2019-04-13 11:32:02

How to configure nginx for css|img|js?

Hello
Config:

events {
    worker_connections  784;
    use epoll;
}

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

    gzip  off;

    server {
        set $my_root "/var/www/html/public_html";
      root $my_root;
        listen 0.0.0.0:80;
        server_name site.loc;
        if ($native = "") {
            set $native "ru";
        }
        rewrite ^/(.*)/$ /$1 permanent;

    charset utf-8;
    source_charset utf-8;

    error_log /var/log/site.ru.error_log error;
    include /etc/nginx/fastcgi_params;

    location /maintenance.html {
        root $my_root/public_html;
        allow all;
    }

    location ~* ^/(signup|login) {
        if ($scheme = http) {
          return 301 http://site.loc/$1/?$query_string;
        }

        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~* /files/avatars/avatar_(\d+)_(\d+)\.jpg {
        expires max;
        access_log off;
        log_not_found off;
        try_files $uri /img/no-avatar/$2.png;
    }

    location ~* /files/blog/post_\d+/(small|medium|large)\.jpg {
        expires max;
        access_log off;
        log_not_found off;
        try_files $uri /img/blog/$1.jpg;
    }

    #location ~*  ^/(js|css|img|fonts)/([a-z0-9-\.\_]+)\.\d+\.(js|css|png|jpg|gif|woff)$ {
    #    add_header Vary Accept-Encoding;
    #    expires max;
    #    access_log off;
    #    log_not_found off;
    #    try_files /$1/$2.min.$3 /$1/$2.$3;
    #}
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
            expires max;
        }

    location ~* ^/(files|img|media|captcha|js|css|fonts) {
        access_log off;
        log_not_found off;
        expires max;
    }

      location ~* \.php$ {
          fastcgi_pass web:9000;
            include        fastcgi_params;

          fastcgi_param SCRIPT_FILENAME    	$my_root/$fastcgi_script_name;
          fastcgi_param SCRIPT_NAME        	$fastcgi_script_name;
          fastcgi_param APPLICATION_ENV    	development;
          fastcgi_param X_NGINX_PAGE_CACHE	$scheme://$server_name$uri$is_args$args;
          fastcgi_param X-Forwarded-For	    $proxy_add_x_forwarded_for;
          fastcgi_index index.php;
      }

      location / {
          index index.php;
            try_files $uri $uri/ /index.php$is_args$args;
        }

    location /xml.php {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers 'Origin, X-Requested-With, Content-Type, Accept';
    }

    location = /gag.html {
          allow all;
      }

    #location / {
    #    try_files $uri /index.php?q=$uri&$args;
      #    rewrite ^(.*)$ /index.php break;
      #    include fastcgi_params;
      #    fastcgi_split_path_info ^(.+\.php)(/.+)$;
      #    fastcgi_index index.php;
      #    fastcgi_pass web:9000;
      #    allow all;

      #    fastcgi_param SCRIPT_FILENAME /var/www/html/public_html/$fastcgi_script_name;
      #}
    }
}

The main page opens, but not a single js|css|img file is loaded, in the console there is a 404 error for them.
Also, I can’t fail through any link deep into the site - also 404.
Tell me what could be the problem?
The ancient zend 1.2 is used, I'm trying to raise the site in docker'e.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question