
使用Nginx配置NodeJs程序(Windows平台)
发布日期:2021-05-09 07:34:57
浏览次数:20
分类:精选文章
本文共 2185 字,大约阅读时间需要 7 分钟。
简介
Nginx("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。
安装
步骤:官网下载Nginx,解压到D盘目录,启动Nginx服务。
官网下载地址:(注意:下载的时候要选择windows版的)
解压到D盘根目录,然后启动Nginx,运行CMD执行命令:
d:cd nginxstart nginx
Nginx基础命令:
nginx -s stop // 停止nginx
nginx -sreload // 重新加载配置文件nginx -squit // 退出nginx使用
假设现在NodeJs的Express有两个站点访问地址:127.0.0.1:3000 | 127.0.0.1::3001 配置负载均衡与健康检测的默认模块,方法如下:
找到配置文件(我的Nginx安装目录为:D:\nginx):D:\nginx\conf\nginx.conf设置替换为如下代码:
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}#ggcmsweb\imagehttp { include mime.types; default_type application/octet-stream; upstream sample { server 127.0.0.1:4030 max_fails=1 fail_timeout=40s; # server 127.0.0.1:4140 max_fails=1 fail_timeout=40s; keepalive 64; } server { listen 8080; charset utf-8; server_name 127.0.0.1; location / { 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_pass http://sample/; proxy_connect_timeout 1; proxy_read_timeout 1; } location ~ .*\.(gif|jpg|jpeg|png|css|js|ico)$ { root /app/webCms/public; expires 1d; } location ~ .*\.(html|shtml)$ { ssi on; ssi_silent_errors on; ssi_types text/shtml; root /app/webCms/public; } location ~ /$ { index index.shtml index.html; root /app/webCms/public; } } server { listen 8081; charset utf-8; server_name 127.0.0.1; location / { root /app/imageAPP/public; autoindex on; autoindex_exact_size off; autoindex_localtime on; expires 30d; } } }
现在访问地址127.0.0.1,Nginx会轮换把请求分别分发给端口3000和端口3001。
假如有一个服务器挂掉,则会一直分配到另一个服务器上,直到检测瘫痪的服务器正常访问之后,恢复轮换请求分发的任务。
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月28日 19时49分10秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
LINQ能不能用系列(一)LINQ to Object 效率比对
2025-04-05
LINQ能不能用系列(二)LINQ to SQL 效率比对
2025-04-05
LinQ:list基础操作
2025-04-05
Linr PS toolkit(Photoshop开发人员辅助工具)
2025-04-05
Lintcode 74 First Bad Version solution 题解
2025-04-05
LintCode A + B Problem
2025-04-05
LintCode Python 简单级题目 8.旋转字符串
2025-04-05
LintCode 第一题fizz buzz
2025-04-05
lintcode-418-整数转罗马数字
2025-04-05
Lintcode: Compare Strings
2025-04-05
LintCode: Longest Common Substring
2025-04-05
Lintcode: Nuts & Bolts Problem
2025-04-05
Lintcode: O(1) Check Power of 2
2025-04-05
Lintcode: Topological Sorting
2025-04-05
LintCode_114 不同的路径,115 不同的路径 II
2025-04-05
linux */10 * * * *,Linux学习之路(10)
2025-04-05
linux - sftp常用命令介绍
2025-04-05
linux -- ubuntu修改IP地址、网关、dns
2025-04-05