Home | Mirror | Search

8. FAQ

8.1. 405 Not Allowed?
8.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?

8.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;
    }
}
				

8.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;
       }

				
comments powered by Disqus