Chinaunix首页 | 论坛 | 博客
  • 博客访问: 382501
  • 博文数量: 112
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 800
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-29 13:41
文章分类

全部博文(112)

文章存档

2020年(1)

2018年(10)

2017年(27)

2016年(18)

2015年(31)

2014年(25)

分类: 系统运维

2018-12-06 23:13:54

系统环境:CentOS6.5
软件包:nginx-1.6.1.tar.gz
一、Nginx编码安装:

点击(此处)折叠或打开

  1. yum install pcre-devel pcre -y
  2. cd /tmp
  3. wget -c http://nginx.org/download/nginx-1.6.1.tar.gz
  4. tar -zxf nginx-1.6.1.tar.gz
  5. cd nginx-1.6.1
  6. #修改Nginx版本信息为WS,其实就是为了不再IE页面不显示nginx的版本。
  7. sed -i -e 's/1.6.1//g' -e 's/nginx\//WS/g' -e 's/"NGINX"/"WS"/g' src/core/nginx.h
  8. useradd www
  9. ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
  10. make
  11. make install
  12. #检查nginx配置文件是否正确,返回ok为正确。
  13. /usr/local/nginx/sbin/nginx -t
  14. #指定nginx配置文件
  15. /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  16. #测试指定的nginx配置文件是否正确;
  17. /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
  18. #启动nginx
  19. /usr/local/nginx/sbin/nginx
  20. #关闭nginx -s stop 快速关闭,不考虑当前是否有请求;
  21. /usr/local/nginx/sbin/nginx -s stop
  22. #关闭nginx -s quit 退出之前完成已经接受的连接请求;
  23. /usr/local/nginx/sbin/nginx -s quit
  24. #重新加载修改后的配置
  25. /usr/local/nginx/sbin/nginx -s reload
  26. #重新打开日志文件;
  27. /usr/local/nginx/sbin/nginx -s reopen


二、配置多个虚拟主机

1、创建两个虚拟主机站点目录

点击(此处)折叠或打开

  1. cd /usr/local/nginx/html
  2. mkdir v{1,2}
  3. for ((i=1;i<=2;i++));do touch v${i}/index.html;echo "i am v${i}"'!' > v${i}/index.html;done

2、修改nginx.conf,添加虚拟主机配置
/usr/local/nginx/conf/nginx.conf

点击(此处)折叠或打开

  1. #user nobody;
  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.     server {
  12.         listen 80;
  13.         server_name localhost

  14.         #charset koi8-r;

  15.         #access_log logs/host.access.log main;

  16.         location / {
  17.             root html;
  18.             index index.html index.htm;
  19.         }    
  20.         error_page 500 502 503 504 /50x.html;
  21.         location = /50x.html {
  22.             root html;
  23.         }
  24.     }
  25.     #virtual hosts config
  26.     server {
  27.         listen 80;
  28.         server_name localhost

  29.         #charset koi8-r;

  30.         #access_log logs/host.access.log main;

  31.         location / {
  32.             root html/v1;
  33.             index index.html index.htm;
  34.         }
  35.     }
  36.     server {
  37.         listen 80;
  38.         server_name localhost

  39.         #charset koi8-r;

  40.         #access_log logs/host.access.log main;

  41.         location / {
  42.             root html/v2;
  43.             index index.html index.htm;
  44.         }
  45.     }

/usr/local/nginx/sbin/nginx -s reload
3、绑定本地hosts文件,IE访问







阅读(1117) | 评论(0) | 转发(0) |
0

上一篇:脚本部署LAMP_DISCUZ

下一篇:Nginx版本升级

给主人留下些什么吧!~~