Страница 1 из 1

Настройка Nginx для Coffee CMS

Добавлено: 03 апр 2022, 14:44
serg
Ниже приведен участок файла /etc/nginx/nginx.conf относящийся к настройкам сервера.

Код: Выделить всё

map $sent_http_content_type $expires {
    default                 off;
    text/html               1d;
    application/javascript  7d;
    text/css                7d;
    image/png               7d;
    image/svg+xml           7d;
}
  
server {
    listen 80;
    server_name www.coffee-cms.com;
    return 301 https://coffee-cms.com$request_uri;
}
  
server {
    listen 80;
    server_name coffee-cms.com;
    root /home/www/coffee-cms.com/htdocs;
    error_log /home/www/coffee-cms.com/error.log warn;
    access_log /home/www/coffee-cms.com/access.log;
    expires 365d;
    gzip on;
    gzip_types text/html text/plain text/css application/json application/javascript;
    client_max_body_size 100m;
    location / {
        index index.html /.cms/index.php;
        # чтобы страницы не скачивались как файлы:
        default_type text/html;
        try_files $uri $uri/ /.cms/index.php?$query_string;
    }
    
    location ~ "/([^/]+\.(zip|gz))$" {
        add_header Content-disposition "attachment; filename=$1";
    }

    location ~ \.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_buffering off;
        fastcgi_request_buffering off;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        expires off;
    }

    location ~ /\. {
        deny  all;
    }

    location /favicon.ico {
        return 204;
        access_log off;
        log_not_found off;
    }
}
  
server {
    listen [201:92ca:1113:af5a:3068:ef27:c0a8:19fa]:80;
    server_name [201:92ca:1113:af5a:3068:ef27:c0a8:19fa];
    root /home/www/coffee-cms.com/htdocs;
    error_log /home/www/coffee-cms.com/error.log warn;
    access_log /home/www/coffee-cms.com/access.log;
    expires 365d;
    gzip on;
    gzip_types text/html text/plain text/css application/json application/javascript;
    client_max_body_size 100m;
    location / {
        index index.html /.cms/index.php;
        # чтобы страницы не скачивались как файлы:
        default_type text/html;
        try_files $uri $uri/ /.cms/index.php?$query_string;
    }

    location ~ \.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_buffering off;
        fastcgi_request_buffering off;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        expires off;
    }

    location ~ /\. {
        deny  all;
    }

    location /favicon.ico {
        return 204;
        access_log off;
        log_not_found off;
    }
}

server {
    listen 443 ssl http2;
    server_name www.coffee-cms.com;
    ssl_certificate /home/www/coffee-cms.com/coffee-cms.com.crt;
    ssl_certificate_key /home/www/coffee-cms.com/coffee-cms.com.key;
    return 301 https://coffee-cms.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name coffee-cms.com;
    root /home/www/coffee-cms.com/htdocs;
    error_log /home/www/coffee-cms.com/error.log warn;
    access_log /home/www/coffee-cms.com/access.log;
    ssl_certificate /home/www/coffee-cms.com/coffee-cms.com.crt;
    ssl_certificate_key /home/www/coffee-cms.com/coffee-cms.com.key;
    expires 365d;
    gzip on;
    gzip_types text/html text/plain text/css application/json application/javascript;
    client_max_body_size 10m;
    location / {
        index index.html /.cms/index.php;
        # чтобы страницы не скачивались как файлы:
        default_type text/html;
        try_files $uri $uri/ /.cms/index.php?$query_string;
    }
    
    location ~ "/([^/]+\.(zip|gz))$" {
        add_header Content-disposition "attachment; filename=$1";
    }

    location ~ \.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_buffering off;
        fastcgi_request_buffering off;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        expires off;
    }

    location ~ /\. {
        deny  all;
    }
    
    location /favicon.ico {
        return 204;
        access_log off;
        log_not_found off;
    }
}