Что не нравится Nginx?
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
................
................
JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo
Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
-----END CERTIFICATE-----
openssl x509 -in /etc/ssl/certs/domains/sea3.ru/cert.crt -noout -text -purpose
Когда захожу в конфиг GNIX на 192.168.0.2, там 2 файла и вот что там прописано:
listen = 127.0.0.1:9001
[site.ru]
listen = /var/lib/php5-fpm/siteru.sock
listen.owner = site
listen.group = site
listen.mode = 0660
...
location ~ \.php$ {
...
fastcgi_pass unix:/var/lib/php5-fpm/siteru.sock;
...
}
pm = ondemand
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5
pm.max_requests = 500
; Перенаправлять вывод процесса в лог
catch_workers_output = yes
; Если скрипт выполняется больше указанного времени, писать отладочную информацию в slowlog
request_slowlog_timeout = 3
; Лог-файл для медленных запросов
slowlog = /var/log/fpm-php/siteru.slow.log
...
location /aaaa {
root /var/www/aaaa;
index index.php index.html index.htm;
location ~ (.+\.php)$ {
try_files $uri = 404;
root /var/www/aaaa/;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/aaaa.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
...
# nslookup portal.tggroup.kz
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: portal.tggroup.kz
Address: 178.62.251.156
1. Постоянный редирект с / на index.phplocation = / { rewrite ^ $scheme://$host/index.php permanent; } location / { deny all; return 404; } location ~* ^/index\.php$ { try_files $uri $uri/ =404; fastcgi_index index.php; fastcgi_pass php5-fpm-sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; }
$host
в порядке приоритета: имя хоста из строки запроса, или имя хоста из поля “Host” заголовка запроса, или имя сервера, соответствующего запросу
...
error_page 404 = @cms;
location / {
try_files /NONEXISTENTFILE @cms;
}
location @cms {
fastcgi_pass unix:/var/lib/php5-fpm/xxxxx.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
include /etc/nginx/fastcgi_params;
}
...
2. Запрещаем любую статику кроме gif|jpg|png|js|css|ttf|woff|icolocation ~* \.(gif|jpg|png|js|css|ttf|woff|ico)$ { try_files $uri =404; expires 30d; }
...
error_page 404 = @cms;
location ~* ^.+\.(gif|jpg|png|js|css|ttf|woff|ico)$ {
expires 30d;
access_log off;
log_not_found off;
}
location / {
try_files /NONEXISTENTFILE @cms;
}
...
http {
....
geo $my_client_ip $denied {
default 1;
127.0.0.1 0;
XX.XX.XX.XX 0; # <- IP1 с которого можно заходить
YY.YY.YY.YY 0; # <- IP2 с которого можно заходить
}
server {
listen 443 ssl;
server_name site.ru;
root /var/www/html/;
...
set $my_client_ip $remote_addr;
if ($http_x_forwarded_client_ip ~ "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") {
set $my_client_ip $http_x_forwarded_client_ip;
}
error_page 403 = @deny;
location @deny {
root /var/www/deny;
rewrite ^(.*)$ /index.html break;
}
location ~* ^/json\.php$ {
if ($denied) {
return 403;
}
try_files /NONEXISTENTFILE @json;
}
location @json {
try_files $uri = 404;
fastcgi_pass unix:/var/lib/php5-fpm/xxxxx.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
}
4. Разрешаем доступ к /admin только с 1-го IP, для /admin/phpmyadmin
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
http {
...
log_format upstream_log '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';
upstream servers {
least_conn;
server ip1;
server ip2 max_fails=3 fail_timeout=30s;
server ip3 max_fails=5 fail_timeout=30s;
keepalive 16;
}
server {
listen 80;
access_log /var/log/nginx/servers-access.log upstream_log;
error_log /var/log/nginx/servers-error.log debug;
location / {
proxy_pass http://servers;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
}
}
http {
# Websocket
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
...
lingering_time 86400;
proxy_ssl_verify off;
proxy_ssl_session_reuse on;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_cache off;
proxy_store off;
set $ssl off;
set $port 80;
if ($scheme = https) {
set $ssl on;
set $port 443;
}
location / {
proxy_pass https://192.168.XX.XX:8443/;
gzip off;
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
proxy_redirect off;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl $ssl;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $port;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Referer "";
}
}
}
server {
listen XX.XX.XX.XX:80 default_server;
server_name _;
return 444;
}
server {
....
root /var/www/mysite.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass unix:/var/lib/php5-fpm/mysite.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
...
}
map $ssl_client_s_dn $ssl_client_s_dn_cn {
default "";
~/CN=(?<CN>[^/]+) $CN;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen XX.XX.XX.XX:80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen XX.XX.XX.XX:80;
listen XX.XX.XX.XX:443 http2 ssl;
server_name www.example.com;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 5m;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_prefer_server_ciphers on;
ssl_session_tickets off;
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/ssl/letsencrypt-ca.pem;
ssl_stapling_responder http://ocsp.int-x3.letsencrypt.org;
return 301 https://example.com$request_uri;
}
server {
listen XX.XX.XX.XX:443 http2 ssl;
server_name example.com;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 5m;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_prefer_server_ciphers on;
ssl_session_tickets off;
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/ssl/letsencrypt-ca.pem;
ssl_stapling_responder http://ocsp.int-x3.letsencrypt.org;
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
root /var/www/html/example.com;
index index.html index.htm;
include acme;
location / {
try_files $uri $uri/ /index.html;
}
}
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0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