Это старая версия документа!


Nginx - Вопросы и Ответы

server {
    listen	80;
    server_name site.com;
    return      301 http://www.site.com$request_uri;
}

server {
    listen       80;
    server_name  www.site.com;
}
  • location /d { rewrite ^ other-folder permanent; }
  • 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; 
    }
  • location @nocached {
    }
    location / {
      if ($cookie_dle_user_id) { return 412; }
    }
    error_page 412 = @nocached;
  • Q: Настройка proxy_pass на удаленный домен по DNS
  • location ^~ /freegeoip/ {
      #use google as dns
      resolver 8.8.8.8;
      proxy_pass http://freegeoip.net/json/$remote_addr;
    }
  • 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
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;

        }

    }
}
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