nginx
nginx :
《精通nginx第二版》
《nginx高性能web服务器详解》
1. web服务器
http 80
安装
升级
虚拟web主机
加密
用户认证
重定向(rewrite)
调优信息
2. 负载均衡 (反向代理)
集群
3. web cache (缓存)
lnmp_soft.tar.gz
解压缩:
# tar -xf lnmp_soft.tar.gz
# cd lnmp_soft
软件的安装方式:
1. yum 安装 :自动解决依赖
2. rpm : 安装单一包
3. apt-get : Ubuntu、debian
4. 源码编译: 一般是tar包
源码编译:
优点: 自主定义配置
步骤:
1.解压:tar -xf
2.进入解压后的目录: cd
3.执行./configure 自定义的内容
4.编译并安装:
# make
# make install
所需的安装包:
gcc pcre-devel
源码编译安装nginx :
1.解压:
# tar -xf nginx-1.10.3.tar.gz
2.进入目录下:
# cd nginx-1.10.3
3.执行./configure
# ./configure
> --user=nginx
> --prefix=/usr/local/nginx
> --group=nginx
> --with-http_ssl_module (加载加密模块)
创建用户nginx :
# useradd nginx
安装支持加密的依赖:
# yum -y install openssl-devel
4.编译并安装:
# make && make install
nginx的管理:
启动:
# /usr/local/nginx/sbin/nginx
停止:
# /usr/local/nginx/sbin/nginx -s stop
重新加载:
# /usr/local/nginx/sbin/nginx -s reload
查看版本信息:
# /usr/local/nginx/sbin/nginx -V
创建软链接:
# ln -s /usr/local/nginx/sbin/nginx /sbin
查看nginx的端口:80
# netstat -anuplt | grep nginx
http://www.nginx.com
//官方网站–下载和售后
http://www.nginx.cn/doc/
//nginx的中文网站
遇到的问题:
现象:未找到nginx.pid
未发现进程
原因:80被占用
httpd
1.10.3 --> 1.12.2
升级:
1.解压:
# tar -xf nginx-1.12.2.tar.gz
2.进入目录:
# cd nginx-1.12.2
3.配置:
# ./configure --user=nginx --group=nginx
–prefix=/usr/local/nginx
–with-http_ssl_module
4.编译:
# make
5.老版本的nginx启动程序备份一份:
# mv /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginxold
6.复制新版本的启动程序:
# cp objs/nginx /usr/local/nginx/sbin
7.更新软件:
# make upgrade
8.验证:
# nginx -V
用户认证:
1.打开网页时,必须输入用户名和密码
2. 用户名tom 密码: 1234
-
修改主配置文件:
vim /usr/local/nginx/conf/nginx.conf
全局配置
events {
局部配置
}
http {
server {
局部配置
}
location / {
局部配置
}
局部配置
}…
server {
listen 80;
server_name localhost;
auth_basic “Input your password:”;
# 认证提示符
auth_basic_user_file “/usr/local/nginx/pass”;
# 认证密码文件
}
…
安装:httpd-tools //提供认证的依赖yum -y install httpd-tools
创建用户和密码:
# htpasswd -c /usr/local/nginx/pass tom
输入两遍密码
//添加新用户时,无需加-c
重新加载:
# nginx -s reload