设为首页 收藏本站
查看: 1256|回复: 0

[经验分享] Nginx的web功能安装

[复制链接]

尚未签到

发表于 2018-11-16 07:59:50 | 显示全部楼层 |阅读模式
  [root@web01~]# yum install pcre pcre-devel -y(下载依赖库)
  [root@web01 ~]# yum install openssl-devel -y(https加密服务会用到)
  [root@web01~]# rpm -qa pcre pcre-devel(检查)
  pcre-devel-7.8-7.el6.x86_64
  pcre-7.8-7.el6.x86_64
  [root@web01~]# rpm -qa openssl openssl-devel
  openssl-devel-1.0.1e-42.el6.x86_64
  openssl-1.0.1e-42.el6.x86_64
  useradd nginx -M -s /sbin/nologin(建立虚拟用户,-M不创建家目录,不允许登录)
  id nginx(检查虚拟用户)
  mkdir -p /application/tools(创建目录)
  cd /application/tools(切换目录)
  rz(上传压缩包,上传到的目录为当前所在目录)
  tar xf nginx-1.6.3.tar.gz (解压)
  cd nginx-1.6.3
  ./configure--prefix=/application/nginx-1.6.3 --user=nginx --group=nginx--with-http_ssl_module --with-http_stub_status_module(初始化数据库)
  make && make install(编译并安装)
  echo $?(检验编译是否成功,输出为0表示正常,1为不正常)
  ln -s /application/nginx-1.6.3/ /application/nginx(创建软连接,不要是用rm-rf删除软连接,会把软连接下面的目录删除的)
  [root@web01~]# /application/nginx/sbin/nginx -h(帮助文件)
  nginxversion: nginx/1.6.3
  Usage:nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
  Options:
  -?,-h        : this help
  -v           : show version and exit
  -V           : show version and configure options then exit
  -t           : test configuration and exit
  -q           : suppress non-error messages during configuration testing

  -s signal    : send signal to a master process: stop, quit, reopen,>  -p prefix    : set prefix path (default: /application/nginx-1.6.3/)
  -c filename  : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out ofconfiguration file
  [root@web01~]# /application/nginx/sbin/nginx -V(显示编译参数)
  nginxversion: nginx/1.6.3
  built bygcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
  TLS SNIsupport enabled
  configurearguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx--with-http_ssl_module --with-http_stub_status_module
  [root@web01~]# cd /application/nginx/conf/(打开配置文件所在目录)
  egrep -v "#|^$" nginx.conf.default >nginx.conf(去掉杂项,nginx.conf.default文件为nginx默认配置文件)
  [root@web01 conf]# vim nginx.conf(d+G为全部删除光标以下内容)
  worker_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  server {
  listen       80;
  server_name  www.etiantian.org;
  location / {
  root   html/www;
  index  index.html index.htm;
  }
  }
  server {
  listen       80;
  server_name  bbs.etiantian.org;
  location / {
  root   html/bbs;
  index  index.html index.htm;
  }
  }
  server {
  listen       80;
  server_name  blog.etiantian.org;
  location / {
  root   html/blog;
  index  index.html index.htm;
  }
  }
  }
  "nginx.conf"35L, 764C 已写入
  mkdir -p ../html/{www,blog,bbs}(创建站点目录文件)
  for n in www bbs blog;do echo "$n.etiantian.org" > ../html/$n/index.html;done(创建主页并写入内容)
  C:\Windows\System32\drivers\etc\hosts(物理机hosts添加下面解析)
  10.0.0.8 www.etiantian.org etiantian.org blog.etiantian.org bbs.etiantian.org
  以下为简化主配置文件
  [root@web01 conf]# mkdir /application/nginx/conf/extra(建立extra目录)
  [root@web01conf]# cat -n nginx.conf(查看行数)
  1 worker_processes  1;
  2 events {
  3     worker_connections  1024;
  4  }
  5 http {
  6     include       mime.types;
  7     default_type application/octet-stream;
  8     sendfile        on;
  9     keepalive_timeout  65;
  10     server {
  11         listen       80;
  12         server_name  www.etiantian.org;
  13         location / {
  14              root   html/www;
  15              index  index.html index.htm;
  16         }
  17     }
  18     server {
  19         listen       80;
  20         server_name  bbs.etiantian.org;
  21         location / {
  22              root   html/bbs;
  23              index  index.html index.htm;
  24         }
  25     }
  26     server {
  27         listen       80;
  28         server_name  blog.etiantian.org;
  29         location / {
  30              root   html/blog;
  31              index  index.html index.htm;
  32         }
  33     }
  34  }
  35
  [root@web01conf]# sed -n '10,17p' nginx.conf >extra/www.conf(追加并创建各自站点配置文件)
  [root@web01conf]# cat extra/www.conf(检查配置文件)
  server {
  listen       80;
  server_name  www.etiantian.org;
  location / {
  root   html/www;
  index  index.html index.htm;
  }
  }
  [root@web01conf]# sed -n '18,25p' nginx.conf >extra/bbs.conf
  [root@web01conf]# cat extra/bbs.conf
  server {
  listen       80;
  server_name  bbs.etiantian.org;
  location / {
  root   html/bbs;
  index  index.html index.htm;
  }
  }
  [root@web01conf]# sed -n '26,33p' nginx.conf >extra/blog.conf
  [root@web01conf]# cat extra/blog.conf
  server {
  listen       80;
  server_name  blog.etiantian.org;
  location / {
  root   html/blog;
  index  index.html index.htm;
  }
  }
  [root@web01conf]# vim nginx.conf(简化主配置文件)
  worker_processes  1;
  error_log logs/error.log error;(指定错误日志,相对路径为nginx安装目录,具体为/application/nginx/logs/error.log)
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  log_format main  '$remote_addr - $remote_user[$time_local] "$request" '(日志文件)
  '$status $body_bytes_sent"$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';
  #nginx vhosts config(各站点配置添加)
  include extra/www.conf;
  include extra/bbs.conf;
  include extra/blog.conf;
  include extra/status.conf;(检查模块)
  }
  ~
  ~
  [root@web01conf]# cat >>/application/nginx/conf/extra/status.conf

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-635569-1-1.html 上篇帖子: 编译安装Nginx-xiaoma 下篇帖子: nginx基本介绍
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表