nginx虚拟主机配置优化

简介:

优化

1
2
[root@web01 conf] # mkdir extra
[root@web01 conf] # vim nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@web01 conf] # cat nginx.conf
worker_processes  1;
events {
     worker_connections  1024;
}
http {
     include       mime.types;
     default_type  application /octet-stream ;
     sendfile        on;
     keepalive_timeout  65;
     include extra /www .conf;
     include extra /bbs .conf;
     include extra /blog .conf;
}
1
2
[root@web01 conf] # cp nginx.conf.20170820 extra/a
[root@web01 conf] # cd extra/
1
2
3
4
5
6
7
8
9
10
[root@web01 extra] # sed -n "18,25p" a    
     server {
         listen       80;
         server_name  bbs.etiantian.org;
         location / {
             root   html /bbs ;
             index  index.html index.htm;
         }
     }
[root@web01 extra] # sed -n "18,25p" a>bbs.conf
1
2
3
4
5
6
7
8
9
[root@web01 extra] # sed -n "10,17p" a 
     server {
         listen       80;
         server_name  www.etiantian.org;
         location / {
             root   html /www ;
             index  index.html index.htm;
         }
     }
1
[root@web01 extra] # sed -n "10,17p" a >www.conf
1
2
3
4
5
6
7
8
9
10
[root@web01 extra] # sed -n "26,33p" a   
     server {
         listen       80;
         server_name  blog.etiantian.org;
         location / {
             root   html /blog ;
             index  index.html index.htm;
         }
     }
[root@web01 extra] # sed -n "26,33p" a >blog.conf
1
[root@web01 extra] # rm -f a

   

     这样就生成了3个虚拟主机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@web01 extra] # cat www.conf 
     server {
         listen       80;
         server_name  www.etiantian.org;
         location / {
             root   html /www ;
             index  index.html index.htm;
         }
     }
[root@web01 extra] # cat bbs.conf 
     server {
         listen       80;
         server_name  bbs.etiantian.org;
         location / {
             root   html /bbs ;
             index  index.html index.htm;
         }
     }
[root@web01 extra] # cat blog.conf 
     server {
         listen       80;
         server_name  blog.etiantian.org;
         location / {
             root   html /blog ;
             index  index.html index.htm;
         }
     }

虚拟主机已包含在配置文件里面了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@web01 extra] # cat ../nginx.conf
worker_processes  1;
events {
     worker_connections  1024;
}
http {
     include       mime.types;
     default_type  application /octet-stream ;
     sendfile        on;
     keepalive_timeout  65;
     include extra /www .conf;
     include extra /bbs .conf;
     include extra /blog .conf;
}

    检查语法:

1
2
3
[root@web01 extra] # ../../sbin/nginx -t
nginx: the configuration  file  /application/nginx-1 .6.3 //conf/nginx .conf syntax is ok
nginx: configuration  file  /application/nginx-1 .6.3 //conf/nginx .conf  test  is successful

    优雅平滑重启(如果平滑重启不生效,那么就-s stop 再nginx启动)

1
[root@web01 extra] # ../../sbin/nginx -s reload

    配置本地dns解析:C:\Windows\System32\drivers\etc\hosts    增加如下dns解析记录

10.0.0.8 www.etiantian.org bbs.etiantian.org blog.etiantian.org

    在windows的ie中验证是否可以打开虚拟主机的站点

www.etiantian.org    bbs.etiantian.org    blog.etiantian.org

wKiom1mZGq6CA1ANAABuj4uZock599.jpg

wKioL1mZGqnRgEGAAABxLTxuzeI873.jpg

wKiom1mZGrCBCWwhAABxjZYH_Ro547.jpg


如果不想每次都修改nginx.conf配置文件,就在配置文件中用*,但是没有优先顺序了。优点是每次新增站点不用修改配置文件了。

wKiom1mZHJ_y8IFoAABCIKJB8GI037.jpg

本文转自sandshell博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1957795如需转载请自行联系原作者

sandshell
相关文章
|
18天前
|
移动开发 前端开发 JavaScript
前端vue2、vue3去掉url路由“ # ”号——nginx配置(一)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
52 0
|
19天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
24 0
|
1月前
|
安全 应用服务中间件 Linux
linux nginx的配置总结
linux nginx的配置总结
19 0
|
18天前
|
前端开发 JavaScript 应用服务中间件
前端vue2、vue3去掉url路由“ # ”号——nginx配置(二)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
53 0
|
3天前
|
应用服务中间件 nginx
nginx配置集群轮训策略
nginx配置集群轮训策略
11 0
|
4天前
|
安全 网络协议 应用服务中间件
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
|
7天前
|
缓存 负载均衡 安全
深入探索Nginx高性能Web服务器配置与优化
【5月更文挑战第7天】本文深入探讨了Nginx的配置与优化,重点介绍了基础配置参数如`worker_processes`、`worker_connections`和`keepalive_timeout`,以及优化策略,包括使用epoll事件驱动模型、开启gzip压缩、启用缓存、负载均衡和安全配置。此外,还提到了性能调优工具,如ab、nginx-stats和nmon,以助于提升Nginx的性能和稳定性。
|
12天前
|
应用服务中间件 PHP nginx
php如何实现检测nginx配置的正确性
请确保在执行此操作时,PHP有足够的权限来执行Nginx命令和访问Nginx配置文件。另外,将上述代码嵌入到您的应用程序中时,要注意安全性,以防止潜在的命令注入攻击。
51 3
|
18天前
|
安全 应用服务中间件 网络安全
linux_nginx中添加ssl配置(open ssl)
linux_nginx中添加ssl配置(open ssl)
25 1
|
18天前
|
JSON JavaScript 前端开发
vue2_vite.config.js的proxy跨域配置和nginx配置代理有啥区别?
vue2_vite.config.js的proxy跨域配置和nginx配置代理有啥区别?
33 1