nginx-基础

一、初识nginx

nginx可以做为web服务器也可以做4层的负载均衡和7层的反向代理,在实际生产环境中应用最多的就是反向代理和web服务器,4层的负载均衡通常由lvs来实现。

nginx安装,在生产中通常编译安装

准备初始环境:yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
下载nginx源码包:nginx-1.12.2.tar.gz
tar xvf nginx-1.12.2.tar.gz -C /apps/
cd nginx-1.2.2
./configure --prefix=/usr/local/src/nginx \ 指定安装的目录
--user=nginx \ nginx的用户
--group=nginx \ nginx的组
--with-http_ssl_module \
--with-http_v2_module
--with-http_realip_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-pcre
--with-stream \ stream模块,在yum安装的时候默认不会安装
--with-stream_ssl_module
--with-stream_realip_module
--add-module=/data/echo-nginx-module echo模块,需要先下载,同样在yum安装的时候默认不会安装(git clone https://github.com/openresty/echo-nginx-module.git)
make && make install
useradd nginx -s /sbin/nologin -u 2000 创建nginx用户和组
chown nginx.nginx -R /usr/local/src/nginx/ 更改权限
编写启动脚本:
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/src/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /usr/local/src/nginx/logs/nginx.pid
ExecStartPre=/usr/local/src/nginx/sbin/nginx -t
ExecStart=/usr/local/src/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start nginx
vim /etc/profile.d/nginx.sh
export PATH=$PATH:/usr/local/src/nginx/sbin
source /etc/profile.d/nginx.sh
nginx编译安装结束。

posted @ 2020-05-12 13:34  世界的我  阅读(135)  评论(0编辑  收藏  举报