Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
nginx:nginx [2016/12/24 19:30] – [Nginx - Вопросы и Ответы] mirocownginx:nginx [2016/12/24 19:31] (текущий) mirocow
Строка 1: Строка 1:
-{{tag>nginx}}+{{tag>nginx install}}
  
 ====== Nginx установка ====== ====== Nginx установка ======
Строка 16: Строка 16:
 </code> </code>
  
-====== Nginx - Вопросы и Ответы ====== 
- 
-  * [[http://mailman.nginx.org/pipermail/nginx-ru/|Архив рассылки]] 
-  * [[http://forum.nginx.org/list.php?21|Форум]] 
- 
- 
-===== Вопросы-Ответы ===== 
- 
-==== Q: Нада перенаправить с site.com на www.site.com ==== 
- 
-<code> 
-server { 
-    listen 80; 
-    server_name site.com; 
-    return      301 http://www.site.com$request_uri; 
-} 
- 
-server { 
-    listen       80; 
-    server_name  www.site.com; 
-} 
-</code> 
- 
-==== Q: Надо перенаправить на другую папку ==== 
- 
-    * location /d { rewrite ^ other-folder permanent; }  
- 
-==== Q: Надо перенаправить GET на другой сервер ==== 
- 
-    * <code> 
-location /d {  
-  rewrite ^ http://server.ru$request_uri? permanent; #301 redirect  
-} 
-</code> 
- 
-==== Q: Надо перенаправить GET|POST на другой сервер ==== 
- 
-    * В данном случае необходимо просто проксировать запрос 
-    * <code> 
-location ~* /d {   
-  proxy_pass http://new-server.ru:80;  
-  proxy_redirect  http://new-server.ru:80 /;  
-  resolver 8.8.8.8;  
-  break;  
-} 
-</code> 
- 
-==== *Q: Надо переправить в другой location, используя ошибку ==== 
- 
-  * <code> 
-location @nocached { 
-} 
-location / { 
-  if ($cookie_dle_user_id) { return 412; } 
-} 
-error_page 412 = @nocached; 
-</code> 
- 
-==== Q: Блокировка IP адресов и подсететей в Nginx ==== 
- 
-  * [[nginx:allow-deny|Блокировка IP адресов и подсететей в Nginx]] 
-   
-  * **Q: Настройка proxy_pass на удаленный домен по DNS** 
-  * <code> 
-location ^~ /freegeoip/ { 
-  #use google as dns 
-  resolver 8.8.8.8; 
-  proxy_pass http://freegeoip.net/json/$remote_addr; 
-} 
-</code> 
- 
-==== Q: Как запаролить location в Nginx ==== 
- 
- 
-  * <code> 
-location ^~ /secure/ { 
- root /www/mysite.com/httpdocs/secure; 
-        auth_basic            "Website development"; 
-        auth_basic_user_file  /www/mysite.com/authfile;  
-} 
-</code> Затем генерируем сам файл, где логин будет admin, а пароль pass <code>php -r "echo 'admin:'. crypt('pass', base64_encode('pass'));" > /www/mysite.com/authfile</code> 
- 
-==== Q: Как перенаправить обработку скрипта в другую папку ==== 
- 
-<code> 
-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; 
- 
-        } 
- 
-    } 
-} 
-</code> 
- 
-==== Q: Количество открытых файлов и их лимиты ==== 
- 
-<code bash> 
-for pid in `pidof nginx`; do echo "$(< /proc/$pid/cmdline)"; egrep 'files|Limit' /proc/$pid/limits; echo "Currently open files: $(ls -1 /proc/$pid/fd | wc -l)"; echo; done 
-</code>