1.Nginx的优势
Nginx是一个高性能的HTTP(解决C10K的问题,就是在一秒之内连接客户端的数目为10k即1万)和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,Nginx以其高性能、稳定性、丰富的功能、简单的配置和 低资源消耗而闻名。也可以作为反向代理服务器、负载均衡器和HTTP缓存。
2.Nginx部署YUM
官方链接http://www.nginx.org
2.1 Nginx版本类型
Mainline version:主线版,及开发板
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy version:遗留的老版本的稳定版
2.2 配置YUM源
在nginx官网,点击文档,找到centos进去,查看配置信息
#sudo yum install yum-utils (安装先决条件)
#vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
#systemctl stop firewalld (关闭防火墙)
#setenforce 0 (关闭selinux)
#getenforce (查看selinux是否关闭)
#yum install -y nginx
#systemctl start nginx
#systemctl enable nginx
#nginx -V
http://192.168.172.149 (测试)
3.Nginx配置文件 (rpm -ql nginx)
/etc/logrotate.d/nginx #日志轮转
/etc/nginx
/etc/nginx/conf.d #子配置文件夹
/etc/nginx/conf.d/default.conf #默认端网站配置文件
/etc/nginx/fastcgi_params #动态网站模块文件-python,php所需的相关变量
/etc/nginx/mime.types #文件关联程序,网站文件类型和相关处理程序
/etc/nginx/modules #模块文件夹,第三方模块
/etc/nginx/nginx.conf #总配置文件
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params/usr/lib/systemd/system/nginx-debug.service #nginx调试程序启动脚本
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx #nginx模块目录
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx #主程序
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.22.0 #文档
/usr/share/doc/nginx-1.22.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz #man手册
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx #缓存各种
/var/log/nginx #日志文件夹
4.Nginx编译参数 (nginx -V)
--prefix=/etc/nginx #安装路径
--sbin-path=/usr/sbin/nginx #程序文件
--modules-path=/usr/lib64/nginx/modules #模块路径
--conf-path=/etc/nginx/nginx.conf #主配置文件
--error-log-path=/var/log/nginx/error.log #错误日志
--http-log-path=/var/log/nginx/access.log #访问日志
--pid-path=/var/run/nginx.pid #程序ID
--lock-path=/var/run/nginx.lock #锁路径,防止重复启动nginx
--http-client-body-temp-path=/var/cache/nginx/client_temp #缓存
--http-proxy-temp-path=/var/cache/nginx/proxy_temp #代理缓存
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp #php缓存
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp #python缓存
--http-scgi-temp-path=/var/cache/nginx/scgi_temp #指定scgi临时临时文件路径
--user=nginx #用户
--group=nginx #组
--with-compat #启用动态模块兼容性
--with-file-aio #aio模块,aio特性会大大提高性能,比如图片站的特点是大量的读io操作,nginx aio 不用等待每次io的结果,有助于并发处理大量io和提高nginx处理效率。
--with-threads #多线程模块
--with-http_addition_module #响应追加
--with-http_auth_request_module #认证模块
--with-http_dav_module #增加上传PUT,DELETE,MKCOL创建集合,COPY和MOVE方法,默认情况下为关闭
--with-http_flv_module #nginx添加MP4,FLV视频支持模块
--with-http_gunzip_module #安装支持gunzip解码方式的模块
--with-http_gzip_static_module #安装支持gzip解码方式的模块
--with-http_mp4_module #安装提供服务端MP4流媒体支持
--with-http_random_index_module #随机主页模块
--with-http_realip_module #nginx获取真实IP模块
--with-http_secure_link_module #安全下载模块
--with-http_slice_module #中文模块
--with-http_ssl_module #安全模块
--with-http_stub_status_module #访问状态
--with-http_sub_module #nginx替换网站响应内容
--with-http_v2_module
--with-mail #邮件客户端
--with-mail_ssl_module #安装邮件支持https模块
--with-stream #安装四层协议的转发、代理或者负载均衡模块
--with-stream_realip_module
--with-stream_ssl_module #安装四成协议的转发、代理或者负载均衡支持https模块
--with-stream_ssl_preread_module
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
5.Nginx基本配置
启动一个新的虚拟机,安装nginx
#vim /etc/nginx/conf.d/testlinux.conf
server{
listen 80;
server_name testlinux.com;
location / {
root /testlinux;
index index.html;
}
}
#mkdir /testlinux
#echo test1 > /testlinux/index.html
#systemctl restart nginx (重启服务)
#vim /etc/hosts
192.168.172.150 testlinux.com (域名解析)
#ping testlinux.com (测试)
#elinks http://testlinux.com