[英]NGINX: Redirect all requests to my localhost port to https/SSL
我有一個運行在localhost:8080
上的NodeJS服務器。 這是HTTPS服務器,而不是HTTP。
因此,該網站在訪問http://localhost8080
時無法正常工作,只能與https://localhost:8080
。
我想使用NGINX將所有來自localhost:8080/whatever
流量重定向到https://localhost:8080/whatever
。
我試過了:
server {
listen 8080;
server_name 127.0.0.1;
return 301 https://$server_name$request_uri;
}
無濟於事-也許Nginx正在以某種方式被我的Node / ExpressJS服務器覆蓋?
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.configure('production', function () {
app.use (function (req, res, next) {
var schema = (req.headers['x-forwarded-proto'] || '').toLowerCase();
if (schema === 'https') {
next();
} else {
res.redirect('https://' + req.headers.host + req.url);
}
});
});
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.use(express.favicon(__dirname + '/public/favicon.ico'));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.