nginx configuration
upstream mall {
server 127.0.0.1:4000;
}
server {
listen 80;
server_name www.a.com;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443;
server_name www.a.com; -sharp
ssl on;
ssl_certificate cert/1_www.a.com_bundle.crt;
ssl_certificate_key cert/2_www.a.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; -sharp
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
add_header "Access-Control-Allow-Origin" "*";
add_header "Access-Control-Allow-Credentials" "true";
add_header "Access-Control-Allow-Methods" "OPTION, POST, GET";
add_header "Access-Control-Allow-Headers" "X-Requested-With, Content-Type";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://mall;
proxy_redirect off;
}
the express interface is as follows
router.post("/login", function (req,res,next) {
var param = {
userName: req.body.userName,
userPwd: req.body.userPwd
}
User.findOne(param,function (err, doc) {
if(err) {
res.json({
status: "1",
msg: err.message
});
}else {
if(doc) {
res.cookie("userId",doc.userId,{
path: "/",
maxAge: 1000*60*60
});
res.cookie("userName",doc.userName,{
path: "/",
maxAge: 1000*60*60
});
res.json({
status: "0",
msg:"",
result:{
userName: doc.userName
}
});
} else {
res.json({
status: "1",
msg:"",
result:""
});
}
}
});
});