I recently maintained a RedHat 5.4 X64 system. The environment is Nginx. When running a forum, I need to submit POST data to the HTML page. All the results are intercepted and an error is displayed: "nginx 405 Not Allowed" is almost no good solution. The only thing we can do is recompile the Nginx source code and edit the conf file.
Later I learned that most web servers such as Apache, IIS, and Nginx do not allow static files to respond to POST requests. Otherwise"HTTP/1.1 405
Method not allowed "error
You need to modify the C source code file in Nginx to the/nginx source code directory/src/http/modules/ngx_http_static_module.c. Find the following code:
The code is as follows: |
Copy code |
If (r-> method & NGX_HTTP_POST ){ Return NGX_HTTP_NOT_ALLOWED; } Comment out the following: /* If (r-> method & NGX_HTTP_POST ){ Return NGX_HTTP_NOT_ALLOWED; } */ |
Then re-compile make
Copy nginx under/nginx source code directory/objs directory to the installed Nginx directory, and restart Nginx to take effect.
For Nginx, you can modify the nginc. conf configuration file, change "405 error" to "200 OK", and configure location to solve the problem as follows:
The code is as follows: |
Copy code |
Server { Listen 80; Server_name www.111cn.net; Index index.html index.htm index. php; Root/data/kiccleaf; If ($ host! = 'Www .111cn.net '){ Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent; } Location ~ . *. (Php | php5 )? $ { Fastcgi_pass 127.0.0.1: 9000; Fastcgi_index index. php; Fcinclude GI. conf; } # Add the following code 405 Error_page 405 = 200 @ 405; Location @ 405 { Root/data/kiccleaf; } } |
You can also simply write it
The code is as follows: |
Copy code |
Server { Listen 80; Server_name www.111cn.net; Index index.html index.htm index. php; Root/data/kiccleaf; If ($ host! = 'Www .111cn.net '){ Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent; } Location ~ . *. (Php | php5 )? $ { Fastcgi_pass 127.0.0.1: 9000; Fastcgi_index index. php; Fcinclude GI. conf; } # Add the following code 405 Error_page 405 = 200 $ uri; } |