nginx

安装调式

下载 nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz 解压
cd nginx-1.14.0
vim auto/cc/gcc 编译时注释 debug

#CFLAGS="$CFLAGS -g"

vim src/core/nginx.h 删除版本信息

 #define NGINX_VER          "nginx/"     即后面的东西

./configure –prefix=/usr/local/nginx –with-http_ssl_module –with-http_stub_status_module –with-threads –with-file-aio 编译
yum install -y gcc 解决依赖性
yum install -y pcre-devel 解决依赖性
yum install -y openssl-devel 解决依赖性
make && make install 检测安装环境 编译
ln -s /usr/local/nginx/sbin/nginx /sbin/ 建立软连接
nginx -t 调试,
启动nginx时,保证80端口不被占用,否则报错;
netstat -antuple | grep 80 查看80 接口

负载均衡

useradd nginx                 建立用户

vim /usr/local/nginx/conf/nginx.conf


 vim /usr/local/nginx/conf/nginx.conf
  1 
  2 user  nginx nginx;
  3 worker_processes  1;         cpu个数  也可以用auto 自己配
  4 events {
  5         use epoll;          默认使用epoll模块
  6         worker_connections      65535;    最大连接数
  7 }
  8 http {                        定义两个RS的 http 网页
  9         upstream test{
 10         server 172.25.254.2:80;
 11         server 172.25.254.3:80;
 12         server 172.25.254.1:8080 backup;  如果2 3 两个主机挂掉 则访问1
 13         }
 14     server {
 15         listen       80;                监听
 16         server_name  www.westos.org;     访问这个域名即可
 17         location / {
 18                 proxy_pass http://test;     定义域名的指向
 19         }
 20         }
 21 }
vim /etc/security/limits.conf    以为修改了最大连接数,所以应当编辑文件
nginx           -       nofile          65536   添加这个
 su - nginx
 ulimit -a

open files                      (-n) 65536  说明监听成功
 nginx
nginx -s reload           重新加载

Ip_hash(保持连接,一开始连接的谁,就一直连接谁)

Nginx–ricci
使用红帽自带的集群管理,server1和server4搭建一个集群(ricci和luci)

nginx 脚本
  1 #!/bin/sh
  2 #
  3 # nginx - this script starts and stops the nginx daemon
  4 #
  5 # chkconfig:   - 85 15
  6 # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
  7 #               proxy and IMAP/POP3 proxy server
  8 # processname: nginx
  9 # config:      /usr/local/nginx/conf/nginx.conf
 10 # pidfile:     /usr/local/nginx/logs/nginx.pid
 11 
 12 # Source function library.
 13 . /etc/rc.d/init.d/functions
 14 
 15 # Source networking configuration.
 16 . /etc/sysconfig/network
 17 
 18 # Check that networking is up.
 19 [ "$NETWORKING" = "no" ] && exit 0
 20 
 21 nginx="/usr/local/nginx/sbin/nginx"
 22 prog=$(basename $nginx)


chmod +x nginx
文章来源: nginx

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:nginx