Home | Mirror | SearchITEYE 博客 | OSChina 博客 | 51CTO 博客

3.4. FAQ

3.4.1. 405 Not Allowed?
3.4.2. nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/info.mydomain.com.conf:112?
3.4.3. 502 Bad Gateway

3.4.1.

405 Not Allowed?

靜態頁面POST會提示405 Not Allowed錯誤.

				
# curl -d name=neo http://www.mydoamin.com/index.html
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>
				
				
server {
    listen       80 default;
    server_name  myid.mydomain.com;

    charset utf-8;
    access_log  /var/log/nginx/myid.mydomain.com.access.log  main;

    if ($http_user_agent ~* ^$){
      return 412;
    }
    ###########################

    location / {
        root   /www/mydomain.com/myid.mydomain.com;
        index  index.html index.php;
        #error_page 405 =200 $request_filename;
    }

    #error_page  404              /404.html;
    #
    error_page 405 =200 @405;
    location @405 {
        #proxy_set_header  Host            $host;
        proxy_method GET;
        proxy_pass http://myid.mydomain.com;

    }


    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
				

3.4.2.

nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/info.mydomain.com.conf:112?

nginx: configuration file /etc/nginx/nginx.conf test failed

使用$request_uri變數可以解決上述問題.

       if ( $request_uri ~ "^/\w+\.xml$") {
            proxy_pass http://www.mydomain.com/xml$request_uri;
			break;
       }

       if ( $request_uri ~ "^/public/datas/\w+\.xml$") {
            proxy_pass http://www.mydomain.com/$request_uri;
			break;
       }

				

3.4.3.

502 Bad Gateway

error.log 提示:

upstream sent too big header while reading response header from upstream?

修改fastcgi配置

location ~ \.php$ {

	fastcgi_buffers 8 16k;
	fastcgi_buffer_size 32k;
	。。。
	。。。
}
				

3.4.1. proxy_pass

nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/www.mydomain.com.conf:25
nginx: configuration file /etc/nginx/nginx.conf test failed
		

在location,if中使用證則匹配proxy_pass末尾不能寫/

	if ($request_uri ~* "^/info/{cn|tw}/{news|info}/\d\.html") {
		proxy_pass http://info.example.com/;
		break;
	}

    location ~ ^/info/ {
                proxy_pass http://info.example.com/;
                break;
    }
		

proxy_pass http://info.example.com/; 改為 proxy_pass http://info.example.com; 可以解決

comments powered by Disqus