Просто готвый пример универсального конфига nginx с использованием php-fpm, и секциями для базовых инструментов (phpMyAdmin, RockMongo) и функционалом для закрытия сайта в режим обслуживания. Сервер одновременно слушает и HTTP, и HTTPS. Все запросы с www перекидываются на адрес «без-www».
Листинг /etc/nginx/sites-available/example.com.conf
:
map $http_cookie $isDevHack { default ""; ~DEVELOPER_SECRET_COOKIE=10101 "/non-existed-location"; } server { listen 80; listen 443 ssl; server_name example.com www.example.com; access_log /var/log/nginx/example.com.access_log; error_log /var/log/nginx/example.com.error_log; root /home/example.com/htdocs/; index index.html index.php; client_max_body_size 15M; location /phpmyadmin/ { root /usr/share/; index index.php index.html index.htm; location ~ ^/mysql-pma/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass unix:/tmp/example.com.pool.socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } } # Redirect www to no-www if ($host = 'www.example.com') { rewrite ^/(.*)$ http://example.com/$1 permanent; } # Only requests to our Host are allowed if ($host !~ ^(example.com|www.example.com)$ ) { return 444; } # Locations location / { if (-f "$isDevHack/home/example.com/maintenance") { return 503; } try_files $uri $uri/ /index.php?$args; } # RockMongo location /rockmongo/ { root /home/example.com/; try_files $uri $uri/ /index.php?$args; } location ~ ^/rockmongo/.*\.php { root /home/example.com/; fastcgi_pass unix:/tmp/example.com.pool.socket; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ \.(php|phtml) { fastcgi_pass unix:/tmp/example.com.pool.socket; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # APC status page location = /apc-status.php { fastcgi_pass unix:/tmp/example.com.pool.socket; fastcgi_param SCRIPT_FILENAME /home/example.com/apc.php; include fastcgi_params; } # Memcached status page location = /memcached-status.php { fastcgi_pass unix:/tmp/example.com.pool.socket; fastcgi_param SCRIPT_FILENAME /home/example.com/memcached.php; include fastcgi_params; } location ~ \.(tpl|xml|log)$ { deny all; } # Errors error_page 503 @maintenance; location @maintenance { rewrite ^(.*)$ /maintenance-mode.html break; } # SSL ssl_certificate /etc/nginx/ssl/example.com.chained.crt; ssl_certificate_key /etc/nginx/ssl/example.com.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; }