Nginx установка
nano /etc/apt/sources.list
deb http://nginx.org/packages/debian/ wheezy nginx deb-src http://nginx.org/packages/debian/ wheezy nginx
$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 $ apt-get update $ apt-get install
Nginx - Вопросы и Ответы
Вопросы-Ответы
Q: Нада перенаправить с site.com на www.site.com
server { listen 80; server_name site.com; return 301 http://www.site.com$request_uri; } server { listen 80; server_name www.site.com; }
Q: Надо перенаправить на другую папку
- location /d { rewrite ^ other-folder permanent; }
Q: Надо перенаправить GET на другой сервер
location /d { rewrite ^ http://server.ru$request_uri? permanent; #301 redirect }
Q: Надо перенаправить GET|POST на другой сервер
- В данном случае необходимо просто проксировать запрос
location ~* /d { proxy_pass http://new-server.ru:80; proxy_redirect http://new-server.ru:80 /; resolver 8.8.8.8; break; }
*Q: Надо переправить в другой location, используя ошибку
location @nocached { } location / { if ($cookie_dle_user_id) { return 412; } } error_page 412 = @nocached;
Q: Блокировка IP адресов и подсететей в Nginx
- Q: Настройка proxy_pass на удаленный домен по DNS
location ^~ /freegeoip/ { #use google as dns resolver 8.8.8.8; proxy_pass http://freegeoip.net/json/$remote_addr; }
Q: Как запаролить location в Nginx
location ^~ /secure/ { root /www/mysite.com/httpdocs/secure; auth_basic "Website development"; auth_basic_user_file /www/mysite.com/authfile; }
Затем генерируем сам файл, где логин будет admin, а пароль pass
php -r "echo 'admin:'. crypt('pass', base64_encode('pass'));" > /www/mysite.com/authfile
Q: Как перенаправить обработку скрипта в другую папку
server { listen 80; server_name site.com; location ^~ /api/target/ { index receive.php; alias /some/path/to/site/target/; location ~ \.php$ { # Fix for server variables that behave differently under nginx/php-fpm than typically expected fastcgi_split_path_info ^(.+\.php)(/.+)$; # Include the standard fastcgi_params file included with nginx include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_index receive.php; # Override the SCRIPT_FILENAME variable set by fastcgi_params fastcgi_param SCRIPT_FILENAME $request_filename; # Pass to upstream PHP-FPM; This must match whatever you name your upstream connection fastcgi_pass phpfpm; #fastcgi_ignore_client_abort off; #try_files $uri =404; } } }
Q: Количество открытых файлов и их лимиты
for pid in`pidof nginx`; doecho"$(< /proc/$pid/cmdline)"; egrep'files|Limit'/proc/$pid/limits; echo"Currently open files: $(ls -1 /proc/$pid/fd | wc -l)"; echo; done