user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
multi_accept on;
}
http {
# запрет обращения к серверу без хоста, например по ip
server {
listen 80;
server_name _;
return 444;
}
log_format upstream '$upstream_addr | $request - [ $upstream_response_time ]';
upstream backender {
# вариант балансировки "Hash и IP hash"
hash $scheme$request_uri; # Для вычисления хэша используется схема (http или https) и полный URL
server site.ru:81 weight=10; #xxx.xxx.xxx.xx1
server 127.0.0.1:81 weight=5; #xxx.xxx.xxx.xx2
}
client_max_body_size 100m;
client_header_buffer_size 4k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
keepalive_requests 100;
reset_timedout_connection on;
client_body_timeout 10;
send_timeout 2;
types_hash_max_size 2048;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_buffers 32 4k;
gzip_comp_level 9;
gzip_disable "msie6";
gzip_http_version 1.1;
gzip_static on;
gzip_vary on;
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
expires 8d;
add_header Pragma public;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
server {
listen 80;
server_name site.ru www.site.ru;
root /var/www/site.ru;
access_log /var/log/nginx/access_log;
#обработка ошибочных
error_page 501 502 503 504 507 = @e5xx;
error_page 403 = @e403;
error_page 404 = @e404;
location @e5xx {
proxy_pass http://127.0.0.1:81/5xx.php?id=5xx&ip=$remote_addr&uri=$request_uri;
recursive_error_pages on;
}
location @e403 {
proxy_pass http://127.0.0.1:81/403.php?id=403&ip=$remote_addr&uri=$request_uri;
recursive_error_pages on;
}
location @e404 {
proxy_pass http://127.0.0.1:81/404.php?id=404&ip=$remote_addr&uri=$request_uri;
recursive_error_pages on;
}
#-- обработка ошибочных
#показываем, откуда брать favicon.ico
location = /favicon.ico {
rewrite ^(.+)$ /media/icons/favicon.ico last;
expires 10m;
}
location / {
proxy_pass http://127.0.0.1:81/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_connect_timeout 6000;
proxy_send_timeout 6000;
proxy_read_timeout 6000;
send_timeout 6000;
proxy_redirect off;
proxy_set_header Connection close;
proxy_pass_header Content-Type;
proxy_pass_header Content-Disposition;
proxy_pass_header Content-Length;
}
location ~* .(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|docx|xlsx|js|otf|eot|svg|ttf|woff|woff2)$ {
root /var/www/site.ru;
index index.php index.html ;
access_log off;
expires 10y;
add_header Last-Modified: $date_gmt;
}
location ~ /.ht {
deny all;
}
}
<VirtualHost *:81>
ServerAdmin admin@site.ru
DocumentRoot /var/www/site.ru
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
# Options Indexes FollowSymLinks MultiViews
Options -Indexes
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteRule ^.htaccess$ - [F]
#http://site.ru/shtroborezy/
RewriteRule ^shtroborezy/?$ index.php?goto=category&category=shtroborezy [L]
.....