主机环境 RedHat6.5 64位
实验环境 服务端 ip172.25.29.1 nginx
服务端 ip 172.25.29.2 apache
服务端 ip 172.25.29.3 apache
测试端 ip 172.25.254.29
安装包 nginx-1.10.1.tar.gz
nginx用作反向代理
服务端1
1. 安装nginx
1.解压及简单配置
[root@server1 mnt]# yum install gcc -y #安装gcc
[root@server1 mnt]# tar zxf nginx-1.10.1.tar.gz #解压nginx压缩包
[root@server1 mnt]# ls
nginx-1.10.1 nginx-1.10.1.tar.gz
[root@server1 mnt]# cd nginx-1.10.1
[root@server1 nginx-1.10.1]# vim auto/cc/gcc #禁止debug调试
178 # debug
179#CFLAGS="$CFLAGS -g"
[root@server1 nginx-1.10.1]# vim src/core/nginx.h #禁止出现nginx版本号,以保证安全性
14 #defineNGINX_VER "nginx/"
2.软件配置(静态)
[root@server1 nginx-1.10.1]# ./configure--prefix=/usr/local/lnmp/nginx --with-http_ssl_module--with-http_stub_status_module
如果出现以下错误
[root@server1 nginx-1.10.1]# yum install pcre-devel -y
重新配置
[root@server1 nginx-1.10.1]# ./configure--prefix=/usr/local/lnmp/nginx --with-http_ssl_module--with-http_stub_status_module
如果出现以下错误
[root@server1 nginx-1.10.1]# yum install openssl-devel -y
重新配置
[root@server1 nginx-1.10.1]# ./configure--prefix=/usr/local/lnmp/nginx --with-http_ssl_module--with-http_stub_status_module
3.编译、链接、安装
[root@server1 nginx-1.10.1]# make
[root@server1 nginx-1.10.1]# make install
2.将nginx作为系统变量,开启nginx
[root@server1nginx-1.10.1]# cd /usr/local/lnmp/nginx/
[root@server1 nginx]# ls
conf html logs sbin
[root@server1 nginx]# ln -s /usr/local/lnmp/nginx/sbin/nginx/usr/local/sbin/ #作软链接将nginx的启动命令作为系统命令
[root@server1 nginx]# nginx -t #检测
nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conftest is successful
[root@server1 nginx]# nginx #打开nginx
[root@server1 nginx]# cd conf/
3.配置文件中模块的修改及测试
[root@server1 conf]# useradd -u 900 -d /usr/local/lnmp/nginx/nginx #创建管理nginx的用户
1.修改用户、添加cpu及绑定cpu
[root@server1 conf]# vim nginx.conf
2 user nginx; #修改nginx的用户
3 worker_processes 2; #工作进程,两块cpu
4 worker_cpu_affinity01 10; #绑定cpu
[root@server1 conf]# nginx -t #检测
nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conftest is successful
[root@server1 conf]# nginx -s reload #重载
测试
[root@server1 conf]# ps aux | grep nginx
[root@server1 conf]# vim nginx.conf
13 events {
14 worker_connections 4096; #支持的最大链接数
15 }
[root@server1 conf]# nginx -t #检测
nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conftest is successful
[root@server1 conf]# nginx -s reload #重载
[root@server1 conf]# vim /etc/security/limits.conf #系统分配给nginx的
51 nginx - nofile 200
52 nginx - nproc 200
[root@server1 conf]# :() { :|:& };: #测试
如果把上面200改成4096,那么系统直接卡死
2.查看nginx状态
[root@server4 conf]# vim nginx.conf #查看nginx状态
57 location /status {
58 stub_status on;
59 access_log off;
60 }
[root@server1 conf]# nginx -t
nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conftest is successful
[root@server4 conf]# nginx -s reload
[root@server1 mnt]# yum install httpd -y
[root@server1 conf]# vim /etc/httpd/conf/httpd.conf
136 Listen 8080 #之前nginx监听80端口,httpd就换了端口
[root@server1 conf]# /etc/init.d/httpd start
Starting httpd: [ OK ]
测试 172.25.29.1/status