1、nginx概述
1.1 nginx的程序架构:master/worker模型;
1> 一个master进程:负责加载和分析配置文件、管理worker进程、服务的平滑升级;
2> 一个或多个worker进程:响应并处理用户请求;
3> 缓存相关的进程:
cache loader:载入缓存对象;
cache manager:管理缓存对象;
1.2 nginx的特性:异步、事件驱动、非阻塞;
1> 并发请求处理机制:通过epoll、select(这2个支持linux);/dev/poll(Solaris)、kevent(BSD);
2> 文件IO:高级IO sendfile,异步,nmap(内存映射);
1.3 nginx的高度模块化:支持动态装载和卸载模块(早期版本不支持DSO机制);
nginx的模块分类:
1>核心模块:core module;
2>标准模块:
HTTP modules:Standard HTTP module,Optional HTTP module;<七层代理>
Mail modules;<七层代理>
Stream module;<四层代理(传输层)>
3> 3rd party modules:第三方模块;
1.4 nginx的功用:
1>静态的web资源服务器(图片服务器、js/html/txt等静态资源服务器);
2>结合FastCGI/uwSGI/SCGI等协议反代动态资源请求;
3>Imap4/pop3协议的反向代理;
4>tcp/udp协议的请求转发;
2、nginx的安装方式:YUM安装方式、源码安装方式;
说明,本机系统版本是”CentOS Linux release 7.4.1708 (Core)”;目前nginx的主线版本是”nginx-1.15.0″,最新稳定版本是” nginx-1.14.0 “;
2.1 yum安装最新稳定版本(非主线版本);
1>配置YUM仓库;
vim /etc/yum.repo.d/nginx.repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
2>安装nginx、启动、加入系统自启动;
~]# yum -y install nginx
~]# systemctl start nginx
~]# systemctl enable nginx
相关文件路径说明:
主配置文件:/etc/nginx/nginx.conf、/etc/nginx/conf.d/
访问日志:/var/log/nginx/access.log
错误日志:/var/log/nginx/error.log
pid文件:/var/run/nginx.pid
主程序文件:/usr/sbin/nginx
YUM安装官方程序包,其默认的编译选项内容:
--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 --lock-path=/var/run/nginx.lock --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 --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --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'
2.2 编译安装nginx-1.14.0;
nginx源码包放置’/usr/local/src’目录中;
1> 前提依赖库安装;
yum -y groupinstall "Development Tools" "Server Platform Development" pcre-devel openssl-devel zlib-devel
2>创建运行nginx服务的用户;
useradd -r nginx
3>编译安装nginx;
~]# cd /usr/local/src ~]# tar zxf nginx-1.14.0.tar.gz ~]# ln -s nginx-1.14.0 nginx ~]# cd nginx ~]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio ~]# make ~]# make install
4>创建nginx的Unit服务脚本,以便使用’systemctl’命令管理nginx服务;
~]# vim /usr/lib/systemd/system/nginx.service
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
5>nginx的启动与加入系统自启动;
~]# systemctl start nginx
~]# systemctl enable nginx
相关文件路径说明:
——————–
主配置文件:/etc/nginx/nginx.conf
访问日志:/var/log/nginx/access.log
错误日志:/var/log/nginx/error.log
pid文件:/var/run/nginx.pid
lock文件:/var/run/nginx.lock