Created
August 31, 2012 06:59
-
-
Save Hyvi/3549759 to your computer and use it in GitHub Desktop.
A static page can not handle POST, so nginx return 405. There is workaround...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# work-around 405 for POST to static URL | |
upstream my-static-server-name { | |
server 11.111.111.111:8080; | |
} | |
. | |
. | |
. | |
# A static page can not handle POST, so nginx return 405. | |
# There is workaround: | |
error_page 405 =200 @405; | |
location = @405 { | |
index index.html index.htm; | |
# needed to forward user's IP address to rails | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_max_temp_file_size 0; | |
proxy_next_upstream error; | |
# 这个设置是不可少的。否则仍然是post方式请求静态文件。 | |
proxy_method GET; | |
if (-f $request_filename) { | |
break; | |
} | |
if (-f $request_filename.html) { | |
rewrite (.*) $1.html break; | |
} | |
if (!-f $request_filename) { | |
proxy_pass http://my-static-server-name; | |
break; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment