源码安装LNMP环境--Nginx篇

Nginx版本:1.15.3
资源下载:http://nginx.org/en/download.html

一、    安装依赖
yum -y install automake 
yum -y install autoconf 
yum -y install libtool 
yum -y install libxml2-devel 
yum -y install libxslt-devel 
yum -y install perl-devel 
yum -y install perl-ExtUtils-Embed 
yum -y install openssl-devel

二、    开始安装
将下载好的安装包通过FTP放到 /usr/local/src 目录下
①    解压并进入到解压目录中
cd /usr/local/src/
tar -zxvf nginx-1.15.3.tar.gz  (yum install -y tar)
cd nginx-1.15.3/
②    创建一个Nginx目录用来存放运行的临时文件夹
mkdir -p /var/cache/nginx
③    通过configure配置安装信息
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--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/nginx.pid \
--lock-path=/var/run/nginx/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=nobody \
--group=nobody \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
④    编译安装
make && make install
⑤    启动Nginx
/usr/sbin/nginx
⑥    查看nginx是否启动
ps -aux | grep nginx  /  ps -ef | grep nginx


三、服务配置
①    创建并编辑文件nginx.service
vim /usr/lib/systemd/system/nginx.service
②    输入以下内容并保存(:wq)
[Unit]
Description=nginx - high performance web server 
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx/nginx.pid
ExecStartPre=/usr/bin/rm -f /var/run/nginx/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
③    设置Nginx开机启动
systemctl enable nginx.service
④    关闭Nginx
pkill -9 nginx
⑤    用systemctl启动Nginx服务
systemctl start nginx.service


四、备注
nginx.service文件配置参数解释

[Unit]
Description=The nginx HTTP and reverse proxy server        描述
After=network.target remote-fs.target nss-lookup.target    服务先后次序与依赖关系

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid    start前,先删除是否有pid文件
ExecStartPre=/usr/sbin/nginx -t      start前,先测试配置文件准确性
ExecStart=/usr/sbin/nginx      启动nginx  
ExecReload=/bin/kill -s HUP $MAINPID   重启,即是向nginx进程发送HUP信号
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target     多用户模式启动

你可能感兴趣的:(后端,PHP,Linux)