开发者社区> 问答> 正文

node.js如何在适用于NodeJS应用程序的AWS负载平衡器中设置Nginx配置?

我一直在努力进行NGINX配置文件的多次迭代,以在AWS的EC2实例上运行NodeJS应用程序。但是我没有成功。任何帮助,将不胜感激。

我的要求:

http请求必须被强制执行https。

www.example.com 应该重定向到 example.com

我能使其在工作http和https分开。

www到非www根本不起作用。

我评论我用来强制逻辑http到https

如果取消注释,则OutOfService在LoadBalancer中会不断出现错误。

我的NGINX配置代码:

server {

listen 80; listen 443;

server_name example.com;

root /opt/bitnami/apache2/htdocs/vdc_live;

location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }

# proxy_set_header X-Forwarded-Proto $scheme; # if ( $http_x_forwarded_proto != 'https' ) # { # return 301 https://$host$request_uri; # }

}

server { server_name www.example.com.com; return 301 $scheme://example.com$request_uri; }

展开
收起
被纵养的懒猫 2019-09-29 18:09:17 469 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
探究 Node.js 的服务端之路 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载