手机百度搜索出现405NotAIIowed to什么意思

node.js - POST request not allowed - 405 Not Allowed - nginx, even with headers included - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
I have a problem in trying to do a POST request in my application and I searched a lot, but I did not find the solution.
So, I have a nodeJS application and a website, and I am trying to do a POST request using a form from this site, but I always end up in this:
and in the console I see :
Uncaught TypeError: Cannot read property 'value' of null
Post "http://name.github.io/APP-example/file.html " not allowed
that is in this line of code :
file.html:
&form id="add_Emails" method ="POST" action=""&
&textarea rows="5" cols="50" name="email"&Put the emails here...
&/textarea&
&INPUT type="submit" onclick="sendInvitation()" name='sendInvitationButton' value ='Send Invitation'/&
&script src="scripts/file.js"&&/script&
function sendInvitation(){
var teammateEmail= document.getElementById("email").
I read many post and a documentation of cross domain but it did not work.
research source 1:
research source 2:
What I am doing now:
I am trying to POST from a different domain of my server :
POST REQUEST :
, github repository
POST LISTENER : " , server localhost ( x-> my ip address)
So, I had the same problem in other files, but I fixed it putting this code in the begginning of each route:
var express = require('express');
var sha1 = require('sha1');
var router = express.Router();
var sessionOBJ = require('./session');
var teams = {}
var teamPlayers = []
router.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "PUT, GET,POST");
and I fixed it doing it.
Now, I am having the same problem, but in this file the only difference is that I deal with SMTP and emails, so I post an email and send an Email to this email I received in the POST request.
THe code is working totally fine with POSTMAN, so, when I test with POSTMAN it works and I can post.
I included this code below instead of the first one I showed but it did not work as well:
router.all('*', function(req, res, next){
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
res.header("Access-Control-Allow-Headers", "Origin, Content-Type, Accept")
res.header("Access-Control-Max-Age", "1728000")
Does someone know how to solve it?
Thank you.
This configuration to your nginx.conf should help you.
location / {
index.html index.
error_page
error_page
# To allow POST on static pages
error_page
This is the real proxy redirection to the intended server.
location / {
proxy_set_header X-Real-IP $remote_
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_
proxy_set_header X-NginX-P
proxy_pass http://xx.xxx.xxx.xxx/;
proxy_set_header Host $
I noticed this wasn't working with a static-first-then-reverse-proxy setup. Here's what that looks like:
location @app {
proxy_pass http://localhost:3000$request_
location / {
try_files $uri $uri/ @
error_page 405 @
1,42511419
I have tried the solution which redirects 405 to 200, and in production environment(in my case, it's Google Load Balancing with Nginx Docker container), this hack causes some 502 errors(Google Load Balancing error code: backend_early_response_with_non_error_status).
In the end, I have made this work properly by replacing Nginx with OpenResty which is completely compatible with Nginx and have more plugins.
With , Now Nginx(OpenResty) could serve static files with POST request properly, here is the config file in my case:
listen 80;
location / {
override_method GET;
proxy_pass http://127.0.0.1:8080;
listen 8080;
location / {
root /var/www/web-
index index.
add_header Cache-Control no-
In the above config, I use override_method offered by
to override the HTTP Method to GET.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 百度搜索数字出现贺卡 的文章

 

随机推荐