
В этой мини-статье приводятся примерные конфигурации виртуального хоста от сети ресурсов, работающих в мультисайтивности. Достаточно сыро, требует доработки, но некоторые вещи можно взять на заметку. Если находите логические ошибки, то отписывайте, посыпайте мою голову пеплом :) Благо, что их здесь много! :) Ещё одна неприятная деталь, - конфиги слиты сразу с двух дедиков — на FreeBSD и на Debian (закомментил, что помню).
Конфигурация сервера
user www-data; # Debian
# user www; # FreeBSD
worker_processes auto;
pid /var/run/nginx.pid; # Debian
error_log /var/log/nginx/error.log warn; # Debian
# timer_resolution 100ms;
worker_rlimit_nofile 16000;
# load_module "/usr/local/libexec/nginx/ngx_http_geoip_module.so";
events {
worker_connections 15000;
accept_mutex on;
use epoll;
# use kqueue; # FreeBSD
# multi_accept on;
}
http {
charset utf-8;
# source_charset utf-8;
include win-utf;
# open_file_cache max=2048 inactive=5m;
# open_file_cache_valid 10m;
# open_file_cache_min_uses 1;
# open_file_cache_errors on;
# geoip_country /etc/nginx/geoip/GeoIP.dat; # Country IP database
# geoip_city /etc/nginx/geoip/GeoLiteCity.dat; # City IP database
## geoip_proxy 192.168.0.0/24;
limit_req_zone $binary_remote_addr zone=gulag:1m rate=60r/m;
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
max_ranges 1;
msie_padding off;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
server_names_hash_bucket_size 128;
server_name_in_redirect off;
send_timeout 1m;
keepalive_timeout 1m;
keepalive_requests 128;
keepalive_disable none;
client_body_timeout 16s;
client_header_timeout 16s;
client_max_body_size 64m;
client_body_buffer_size 1m;
ignore_invalid_headers on;
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging
##
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format nexus '$remote_addr [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" - "$http_user_agent"';
log_format combo2 '$http_x_real_ip - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" - $remote_addr';
# access_log /var/log/nginx/access.log main;
access_log off;
##
# Gzip Settings
##
gzip on;
# gzip_disable "msie6";
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_min_length 4097;
# gzip_proxied expired no-cache no-store private auth;
gzip_proxied any;
gzip_comp_level 3;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rs
# Proxy Cache Settings
proxy_cache_path /var/cache levels=1:2 keys_zone=reverse_cache:60m inactive=90m max_size=1000m;
##
# Virtual Host Configs
##
include /usr/local/etc/nginx/conf/*.host;
}
Виртуальный хост для 4-ех доменов
Конфигурация виртуального хоста (сервер Nginx 1.10.*) для мультисайтинга. Домены отображаются в директории /dom/xop.eu/*. В регулярках ничего не понимаю, поэтому, если Вы можете посоветовать модификации конфига для более адекватного и оптимизированного вида, то это только приветствуется.
server {
listen 80;
##
# HTTPS Only
##
# listen 443 ssl http2;
## listen 11.22.33.44:443 ssl; # Failover IP
# include /usr/local/etc/nginx/snippets/ssl-params.conf;
# ssl_certificate /etc/letsencrypt/live/xor.eu/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/xor.eu/privkey.pem;
server_name xor.eu www.xor.eu nop.eu not.eu;
limit_conn perip 16;
limit_conn perserver 256;
if ($http_host ~ "\.$" ){
rewrite ^(.*) $scheme://$host$1 permanent;
}
set $homepath "/var/sites/xor.eu";
root $homepath/www;
index index.html index.php; # If your cache stored in index.html
error_log /var/sites/xor.eu/log/error.log;
access_log /var/sites/xor.eu/log/access.log main buffer=64k;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~* \.(bak|log)$ {
allow 127.0.0.1;
deny all;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
try_files $uri $uri/ @rewrite;
}
location ~* \.(png|jpe?g|gif|woff|woff2|eot)$ {
expires 1d;
access_log off;
gzip off;
log_not_found off;
try_files $uri $uri/ @rewrite;
}
location ~* \.(css|js|xml|json|txt|htm?l|bmp|ico|svg|ttf|otf|cur)$ {
expires 1d;
access_log off;
log_not_found off;
try_files $uri $uri/ @rewrite;
}
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
expires 1h;
rewrite ^/css/main.css /dom/$http_host/stat/main.css last;
rewrite ^/(.*)\.xml$ /dom/$http_host/stat/$1.xml last;
rewrite ^/sitemap.htm /dom/$http_host/stat/sitemap.htm last;
rewrite ^/favicon.ico /dom/$http_host/stat/favicon.ico last;
rewrite ^/favicon.png /dom/$http_host/stat/favicon.png last;
rewrite ^/photo/(.*)$ /dom/$http_host/stat/photo/$1 last;
rewrite ^/pdf/(.*)$ /dom/$http_host/stat/pdf/$1 last;
rewrite ^/robots.txt /dom/$http_host/stat/robots.txt last;
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/proxy_params;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:$homepath/temp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
P.S.: К 2020-му несколько устарело, многие куски конфига можно засунуть в сниппеты и т.д.
Вы можете войти под своим логином или зарегистрироваться на сайте.