@源码安装nginx及源码包下载
一、下载源码包
复制链接打开
链接:*https://pan.baidu.com/s/17gUkX-UC9GHTf3rkY8aV_Q*
提取码:**1314**
~~~~复制这段内容后打开,操作更方便哦~~~~
二、安装nginx
#下载Nginx源码包
[root@web01 ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
#解压Nginx源码包到/opt目录下,并查看Nginx源文件结构
[root@web01 ~]# tar -xzvf nginx-1.12.2.tar.gz
#安装nginx编译安装所需要的的依赖
[root@web01 ~]# yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim
Nginx依赖于pcre、zlib、openssl,在编译前配置时如果有问题
使用yum方式安装三个包(pcre-devel、zlib-devel、openssl-devel)
#进行编译前配置
[root@web01 opt]# cd /opt
[root@web01 opt]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
#执行多核编译安装
[root@web01 opt]# make - && make install
#启动nginx,提前先关闭防火墙、seLinux
[root@web01 opt]# setenforce 0
[root@web01 opt]# systemctl stop firewalld
[root@web01 opt]# systemctl disable firewalld
#切换到安装目录/usr/local/nginx,查看目录的结构
[root@web01 opt]# cd /usr/local/nginx
[root@web01 nginx ]# pwd
[root@web01 nginx ]# ls
#然后启动Nginx
[root@web01 nginx ]# /usr/local/nginx/sbin/nginx
#检查Nginx进程是否启动
[root@web01 ~ ]# ps aux | grep nginx
root 3949 0.0 0.1 46436 1152 ? Ss 4月30 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
www 3950 0.0 0.2 46836 2180 ? S 4月30 0:00 nginx: worker process
root 6295 0.0 0.0 112676 976 pts/1 S+ 03:00 0:00 grep --color=auto nginx
3查看Nginx使用的端口号
[root@web01 ~]# netstat -tlnp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3949/nginx: master
#使用本地主机的浏览器访问虚拟机上的Nginx服务器
停止nginx
停止Nginx的三种方式
# 1). 立即停止Nginx服务
[root@web01 ~]# /usr/local/nginx/sbin/nginx -s stop
# 2).完成当前任务后停止
[root@web01 ~]# /usr/local/nginx/sbin/nginx -s quit
# 3).杀死Nginx进程(两种方式)
[root@web01 ~]# killall nginx
[root@web01 ~]# pkill nginx
#nginx添加环境变量(使用软连接将nginx链接到/usr/local/sbin)
[root@web01 ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin #建立软连接
[root@web01 ~]# ll /usr/local/sbin/ | grep "nginx"
#显示当前环境变量PATH
[root@web01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#编辑.bash_profile文件(添加环境变量)
[root@web01 ~]# vim ~/.bash_profile
..........
export PATH=$PATH:/usr/local/nginx/sbin
......
#重载引用.bash_profile文件(生效配置文件)
[root@web01 ~]# source ~/.bash_profile
#常用nginx命令(启动、停止、)
# 启动nginx
[root@web01 ~]# nginx
# 停止nginx
[root@web01 ~]# nginx -s stop
[root@web01 ~]# nginx -s quit
三、源码安装nginx,自动化安装脚本实现
#!/bin/bash
# installation configuration
NGINX_VERSION=1.12.2
NGINX_SRC_PATH=/root
NGINX_BIN_PATH=/usr/local/nginx
# disable firewall
systemctl stop firewalld
setenforce 0
# installation dependence
yum install -y pcre-devel zlib-devel openssl-devel wget gcc
# download nginx source package
cd ${NGINX_SRC_PATH}
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
# unzip source package
tar -xzvf nginx-${NGINX_VERSION}.tar.gz
cd ./nginx-${NGINX_VERSION}
# install nginx
./configure --prefix=${NGINX_BIN_PATH} --with-http_ssl_module
make & make install
# start nginx service
cd ${NGINX_BIN_PATH}/sbin
./nginx
# END
本文来自博客园,作者:ଲ一笑奈&何,转载请注明原文链接:https://www.cnblogs.com/zeny/p/15121567.html