设为首页 加入收藏

TOP

Nginx(二)(一)
2017-10-13 10:21:06 】 浏览:1439
Tags:Nginx

利用include功能优化nginx的配置文件

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

写配置文件

  1. [root@lnmp conf]# mkdir extra
  2. [root@lnmp conf]# sed -n '18,25p' nginx.conf.base-name >extra/bbs.conf
  3. [root@lnmp conf]# cat extra/bbs.conf
  4.     server {
  5.         listen 80;
  6.         server_name bbs.etiantian.org;
  7.         location / {
  8.             root html/bbs;
  9.             index index.html index.htm;
  10.         }
  11.     }
  12. [root@lnmp conf]# sed -n '26,33p' nginx.conf.base-name >extra/blog.conf
  13. [root@lnmp conf]# cat extra/blog.conf
  14.    server {
  15.         listen 80;
  16.         server_name blog.etiantian.org;
  17.         location / {
  18.             root html/blog;
  19.             index index.html index.htm;
  20.         }
  21.     }
  22. [root@lnmp conf]# cat extra/www.conf
  23.     server {
  24.         listen 80;
  25.         server_name www.etiantian.org;
  26.         location / {
  27.             root html/www;
  28.             index index.html index.htm;
  29.         }
  30.     }

重启服务

  1. [root@lnmp conf]# /application/nginx/sbin/nginx -t
  2. nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
  3. nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
  4. [root@lnmp conf]# /application/nginx/sbin/nginx -s reload

测试

  1. [root@lnmp conf]# curl www.etiantian.org
  2. www.etiantian.org
  3. [root@lnmp conf]# curl bbs.etiantian.org
  4. bbs.etiantian.org
  5. [root@lnmp conf]# curl blog.etiantian.org
  6. blog.etiantian.org

nginx虚拟主机别名的配置

  1. [root@lnmp conf]# cat extra/www.conf
  2.     server {
  3.         listen 80;
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇解决debian (Friendly ARM 嵌入.. 下一篇数据库MySQL调优实战经验总结

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目