网站首页 > 技术教程 正文
声明:本文乃“运维家”原创,转载请注明出处,更多内容请关注公众号“运维家”。
主旨
在我们使用nginx的过程中,由于他本身性能极好,所以往往对应着不同的项目,且不同的项目配置也不尽相同,这种情况下如果每个项目都对应着自己的配置文件的话,会有很强的阅读性和极高的易维护度。
环境
linux环境
nginx环境
PS:nginx如何安装的话,可以关注公众号“运维家”,后台回复“106”进行查看。
配置初衷
有三个项目,分别是test_a,test_b,test_c,想使用三个不同的配置文件来代理这三个项目,在这里的话不同的项目,使用不同的html代替了,可以理解哈,使用端口映射如下:
test_a:10000
test_b:10001
test_c:10002
需要说明一点的是,每个配置文件里面都可以映射多个端口,并不是说只能映射一个端口。
创建代替项目的三个html文件:
[yunweijia@localhost nginx]$ pwd
/usr/local/nginx
[yunweijia@localhost nginx]$ cd html/
[yunweijia@localhost html]$ echo 'my name is test_a' > test_a.html
[yunweijia@localhost html]$ echo 'my name is test_b' > test_b.html
[yunweijia@localhost html]$ echo 'my name is test_c' > test_c.html
[yunweijia@localhost html]$ ls
test_a.html test_b.html test_c.html
[yunweijia@localhost html]$
开始配置
在http中添加include参数,并指定配置文件存放路径,意思是加载该路径下的配置文件。
[yunweijia@localhost nginx]nbsp;pwd
/usr/local/nginx
[yunweijia@localhost nginx]nbsp;vim conf/nginx.conf
# 在http{}里面添加如下信息
include /usr/local/nginx/conf.d/*.conf;
[yunweijia@localhost nginx]$
上面配置的意思是,nginx程序在启动的时候自动去加载“/usr/local/nginx/conf.d”目录下以“.conf”结尾的配置文件。
在指定目录下新建我们的项目配置文件,如下:
[yunweijia@localhost nginx]$ mkdir conf.d
[yunweijia@localhost nginx]$ cd conf.d/
[yunweijia@localhost conf.d]$ touch {test_a,test_b,test_c}.conf
[yunweijia@localhost conf.d]$ ls
test_a.conf test_b.conf test_c.conf
[yunweijia@localhost conf.d]$
新建的项目配置文件中书写nginx配置的时候,直接从server开始书写,例子如下:
剩余内容请关注微信公众号 “运维家” ,回复 “108” 查看。
猜你喜欢
- 2024-09-22 后端必备 Nginx 配置(nginx配置前后端)
- 2024-09-22 实例分享:Nginx学习之反向代理WebSocket配置实例
- 2024-09-22 Nginx 最全操作——nginx配置(2)(nginx配置cgi)
- 2024-09-22 「Nginx」02节-Nginx location 匹配规则详解
你 发表评论:
欢迎- 08-06linux 和 windows文件格式互相转换
- 08-06谷歌 ChromeOS 已支持 7z、iso、tar 文件格式
- 08-06Linux下比较文件内容的6种方法
- 08-06文件格式及功能汇总
- 08-0610个Linux文件内容查看命令的实用示例
- 08-06Linux-如何区分不同文件类型
- 08-06Zabbix技术分享——监控windows进程资源使用情况
- 08-06Linux系统卡顿?学会ps命令这三招,轻松定位问题进程
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)