Welcome! Log In Create A New Profile

Advanced

Nginx Proxy pass

Posted by leult 
Nginx Proxy pass
June 27, 2021 12:57PM
Access to XMLHttpRequest at 'http://socicraftengine-env.eba-szkirmr3.us-east-2.elasticbeanstalk.com/api/auth/login' from origin 'http://socicraft-platform.s3-website.us-east-2.amazonaws.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am getting this error when I try to hit the server, I tried so many things but it is not working .....
SERVER - RUNNING on EBS aws -nodejs
SERVER CORS setup

app.use((req, res, next) => {
const allowedOrigins = [
"http://socicraft-platform.s3-website.us-east-2.amazonaws.com/",
"http://socicraft-platform.s3-website.us-east-2.amazonaws.com",
"http://localhost:3000",
];
const origin = req.headers.origin;
if (allowedOrigins.includes(origin)) {
res.setHeader("Access-Control-Allow-Origin", origin);
}
res.setHeader(
"Access-Control-Allow-Headers",
"Origin,X-Requested-With,Content-Type,Cookie-Accept,x-auth-user"
);
res.setHeader("Access-Control-Expose-Headers", "x-auth-user");
res.setHeader(
"Access-Control-Allow-Methods",
"PUT, POST, GET, DELETE, OPTIONS"
);
res.setHeader("Access-Control-Allow-Credentials", true);
next();
});

I tried to add this script on nginx

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;

proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Origin $http_origin always;

if ($request_method = 'OPTIONS'){

add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers 'x-auth-user, Origin, X-Requested-With, Content-Type, Cookie-Accept';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;


}

}



any help appreciated thank you for your time
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 52
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready