I am building a web server using Nginx and express.
By redirecting requests from port 80 to port 443, Nginx only allows encrypted connections. And Port 443 forwards the request to express.
Nginx's conf settings are:
server {
listen 80;
server_name api.domain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name api.domain.com;
ssl_certificate /path
ssl_certificate_key /path
...
location / {
proxy_pass http://localhost:3000;
}
}
express uses CORS middleware.
var app = express();
var cors = require('cors');
app.use(cors());
var server = http.createServer(app).listen(3000, 'localhost', function() { ... });
I tried something like https://www.steemcoinpan.com/sct/@morning/express-nginx-proxy-ssl-websocket, but it still doesn't work.
What settings do I need?
※ Added
If I call an API like 'http://api.domain.com/login', [Access to XMLHttpRequest at'http://api.domain.com/login' from origin'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.] error message is displayed.