雾里看浮光
不管遇到什么事情,都要调整好自己的心态,用最好的自己重新开始,自甘堕落只会越来越糟糕!加油!

 

CentOS Linux 7.7操作系统

Nginx安装部署文档

 

编写人

雾里看浮光

版  本

SBL-Linux-02-01

博  客

https://www.cnblogs.com/LuckyHaTech/

 

一、系统版本

CentOS Linux release 7.7.1908 (Core)

二、软件版本

2.1.Pcre软件包

pcre-8.43.tar.gz

2.2.Zlib软件包

zlib-1.2.11.tar.gz

2.3.OpenSSL软件包

openssl-1.1.1c.tar.gz

2.4.Nginx软件包

nginx-1.16.0.tar.gz

三、软件安装

3.1.创建指定目录

[root@localhost ~]# mkdir -p /usr/local/data/lnmp

3.2.安装依赖组件

[root@localhost ~]# yum -y install gcc gcc-c++

3.3.安装Pcre库

[root@localhost ~]# tar -xzf pcre-8.43.tar.gz -C /usr/local/data/lnmp/

[root@localhost ~]# cd /usr/local/data/lnmp/pcre-8.43

[root@localhost pcre-8.43]# ./configure --prefix=/usr/local/data/lnmp/pcre

[root@localhost pcre-8.43]# make

[root@localhost pcre-8.43]# make install

3.4.安装Zlib库

[root@localhost ~]# tar -xzf zlib-1.2.11.tar.gz -C /usr/local/data/lnmp/

[root@localhost ~]# cd /usr/local/data/lnmp/zlib-1.2.11/

[root@localhost zlib-1.2.11]# ./configure --prefix=/usr/local/data/lnmp/zlib

[root@localhost zlib-1.2.11]# make

[root@localhost zlib-1.2.11]# make install

3.5.安装OpenSSL库

[root@localhost ~]# tar -xzf openssl-1.1.1c.tar.gz -C /usr/local/data/lnmp/

[root@localhost ~]# cd /usr/local/data/lnmp/openssl-1.1.1c/

[root@localhost openssl-1.1.1c]# ./config --prefix=/usr/local/data/lnmp/openssl

[root@localhost openssl-1.1.1c]# make

[root@localhost openssl-1.1.1c]# make install

*配置软链接*

[root@localhost openssl-1.1.1c]#

ln -s /usr/local/data/lnmp/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1

[root@localhost openssl-1.1.1c]#

ln -s /usr/local/data/lnmp/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

*设置环境变量*

[root@localhost openssl-1.1.1c]# echo 'export PATH=$PATH:/usr/local/data/lnmp/openssl-1.1.1c/bin'>>/etc/profile

[root@localhost openssl-1.1.1c]# source /etc/profile

*删除软链接*

[root@localhost openssl-1.1.1c]# rm /usr/lib64/libssl.so.1.1

[root@localhost openssl-1.1.1c]# rm /usr/lib64/libcrypto.so.1.1

3.6.安装Nginx包

[root@localhost ~]# groupadd nginx

[root@localhost ~]# useradd -r -g nginx nginx

[root@localhost ~]# tar -xzf nginx-1.16.0.tar.gz -C /usr/local/data/lnmp/

[root@localhost ~]# cd /usr/local/data/lnmp/nginx-1.16.0/

[root@localhost nginx-1.16.0]#

./configure --prefix=/usr/local/data/lnmp/nginx \

--sbin-path=/usr/local/data/lnmp/nginx/sbin/nginx \

--modules-path=/usr/local/data/lnmp/nginx/modules \

--conf-path=/usr/local/data/lnmp/nginx/conf/nginx.conf \

--error-log-path=/usr/local/data/lnmp/nginx/error/error.log \

--pid-path=/usr/local/data/lnmp/nginx/pid/nginx.pid \

--lock-path=/usr/local/data/lnmp/nginx/lock/nginx.lock \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_mp4_module \

--with-http_stub_status_module \

--http-log-path=/usr/local/data/lnmp/nginx/access/access.log \

--http-client-body-temp-path=/usr/local/data/lnmp/nginx/client \

--http-proxy-temp-path=/usr/local/data/lnmp/nginx/proxy \

--http-fastcgi-temp-path=/usr/local/data/lnmp/nginx/fcgi \

--http-uwsgi-temp-path=/usr/local/data/lnmp/nginx/uwsgi \

--http-scgi-temp-path=/usr/local/data/lnmp/nginx/scgi \

--with-pcre=/usr/local/data/lnmp/pcre-8.43 \

--with-zlib=/usr/local/data/lnmp/zlib-1.2.11 \

--with-openssl=/usr/local/data/lnmp/openssl-1.1.1c

[root@localhost nginx-1.16.0]# make

[root@localhost nginx-1.16.0]# make install

3.7.检验安装是否成功

[root@localhost ~]# ls /usr/local/data/lnmp/nginx

*配置软链接*

[root@localhost ~]# ln -s /usr/local/data/lnmp/nginx/sbin/nginx /usr/local/bin/

[root@localhost ~]# nginx -t

四、配置修改

4.1.添加Nginx为系统服务

[root@localhost ~]# vim /lib/systemd/system/nginx.service

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/data/lnmp/nginx/sbin/nginx

ExecReload=/usr/local/data/lnmp/nginx/sbin/nginx -s reload

ExecStop=/usr/local/data/lnmp/nginx/sbin/nginx -s stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

4.2配置nginx.conf文件(访问PHP使用)

[root@localhost ~]# vim /usr/local/data/lnmp/nginx/conf/nginx.conf

*修改nobody为nginx *

user   nginx nginx;

*在index后面添加index.php

#access_log logs/host.access.log main;

#

location / {

root html;

index index.html index.htm index.php;

}

*取消注释和修改SCRIPT_FILENAME后面的文件路径*

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /usr/local/data/lnmp/nginx/html$fastcgi_script_name;

include fastcgi_params;

 }

4.3.常用操作命令

*设置开机自启*

[root@localhost ~]# systemctl daemon-reload

[root@localhost ~]# systemctl enable nginx.service

*常用命令*

[root@localhost ~]# systemctl start nginx.service

[root@localhost ~]# systemctl stop nginx.service

[root@localhost ~]# systemctl status nginx.service

[root@localhost ~]# systemctl restart nginx.service

*重新加载配置文件*

[root@localhost ~]# nginx -s reload

五、操作验证

打开浏览器输入IP访问:

http://192.168.10.11

访问Nginx成功后则显示:

六、Nginx编译参数详解

*指定安装目录路径*

./configure --prefix=/usr/local/data/lnmp/nginx

*指定可执行文件路径*

--sbin-path=/usr/local/data/lnmp/nginx/sbin/nginx

*指定第三方模块的存放路径*

--modules-path=/usr/local/data/lnmp/nginx/modules

*指定配置文件路径*

--conf-path=/usr/local/data/lnmp/nginx/conf/nginx.conf

*指定错误日志文件路径*

--error-log-path=/usr/local/data/lnmp/nginx/error/error.log

*指定PID文件路径*

--pid-path=/usr/local/data/lnmp/nginx/pid/nginx.pid

*指定lock文件路径*

--lock-path=/usr/local/data/lnmp/nginx/lock/nginx.lock

*指定程序运行时的非特权用户*

--user=nginx

*指定程序运行时的非特权用户组*

--group=nginx

*启用ngx_http_ssl_module支持*

--with-http_ssl_module

*启用ngx_http_flv_module支持*

--with-http_flv_module

*启用ngx_http_mp4_module支持*

--with-http_mp4_module

*启用ngx_http_stub_status_module支持*

--with-http_stub_status_module

*设定access log日志路径*

--http-log-path=/usr/local/data/lnmp/nginx/access/access.log

*设定http客户端请求临时文件路径*

--http-client-body-temp-path=/usr/local/data/lnmp/nginx/client

*设定http代理临时文件路径*

--http-proxy-temp-path=/usr/local/data/lnmp/nginx/proxy

*设定http fastcgi临时文件路径*

--http-fastcgi-temp-path=/usr/local/data/lnmp/nginx/fcgi

*设定http uwsgi临时文件路径*

--http-uwsgi-temp-path=/usr/local/data/lnmp/nginx/uwsgi

*设定http scgi临时文件路径*

--http-scgi-temp-path=/usr/local/data/lnmp/nginx/scgi

*指向pcre库目录*

--with-pcre=/usr/local/data/lnmp/pcre-8.43

*指向zlib库目录*

--with-zlib=/usr/local/data/lnmp/zlib-1.2.11

*指向openssl库目录*

--with-openssl=/usr/local/data/lnmp/openssl-1.1.1c

posted on 2019-08-31 14:49  雾里看浮光  阅读(711)  评论(0编辑  收藏  举报