linux运维之nginx-web服务应用

1.下载安装包:nginx-1.14.0.tar.gz
2.解压:tar zxf nginx-1.14.0.tar.gz
3.cd nginx-1.14.0/src/core


4.vim nginx.h
修改14行为: #define NGINX_VER          "nginx"


5.cd nginx-1.14.0/auto/cc
6.vim gcc
注释掉172行


7.cd nginx-1.14.0
yum install gcc openssl-devel pcre-devel -y

#########源码编译三部曲: ./configure     make   make install##############必须按顺序全部执行
然后执行:./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio


8.make

没有报错,执行下一步
9.make install

编译完成
10.ln -s /usr/local/nginx/sbin/nginx /sbin/
## 执行这条命令后,就可以用执行nginx直接开启服务

## nginx -t  ##检测语法错误
nginx -s stop 关闭服务
nginx -s reload 重启服务

##上面执行命令时出现的报错都是用为服务没开启,应该先开启在关闭或者重载


11.检测: curl IP -I


12.nginx默认发布目录在/usr/local/nginx/html
默认发布文件:index.html

####配置nginx虚拟主机##
13.cd /usr/local/nginx/conf/
vim nginx.conf
  2 user  nginx nginx;
  3 worker_processes  1;
  4 worker_cpu_affinity 01;

  13 events {
  14     worker_connections  65535;
  15 }

  18 http {
  19         upstream westos {
  20         #ip_hash;   #哈希算法:一但检测到ip,不改变后端服务器
  21         server 172.25.6.2:80;
  22         server 172.25.6.3:80;
  23         #server 127.0.0.1 backup; ##当2和3服务全部关掉后, 默认访问本机
  24         }


  124         server {
  125                 listen 80;
  126                 server_name www.westos.org;
  127
  128                 location / {
  129                 proxy_pass http://westos;
  130                 }
  131         }

14.useradd -M -d /usr/local/nginx/ nginx   # 指定用户家目录创建用户

15.nginx -t    检测有没有语法错误,如果有检查文件是否有错误
16.nginx -s reload


17.vim /etc/security/limits.conf
在最后写入:
nginx   -       nofile  65536


18.物理机里检测:
curl www.westos.org

#####给服务添加模块(sticky)########
1.需要下载nginx的旧版本,这里用10版本
2.再下载 nginx-sticky-module-ng.tar.gz
3.#####停用之前的nginx######
nginx -s stop


4.解压下载的两个模块

cd nginx-1.10.1
5../configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --add-module=/root/nginx-sticky-module-ng
#  要将新安装的nginx放到其他目录,否则以前的版本将被完全覆盖
6.make
7.make install


8.cd /opt/nginx/conf/
9.cp /usr/local/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf


10.vim /opt/nginx/conf/nginx.conf
写入:
 21         sticky;


11./opt/nginx/sbin/nginx -t
## 必须用绝对路径,否则会跟之前的版本冲突
12./opt/nginx/sbin/nginx   ##打开服务


13.在浏览器中测试,因为有sticky算法,所以不会发生轮询,换个浏览器就会发生变化

猜你喜欢

转载自blog.csdn.net/gd0306/article/details/81326568
今日推荐