Linux下源码安装并配置Nginx
实验环境
- 一台最小化安装的CentOS 7.3 虚拟机
安装nginx
安装nginx依赖包
yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim
Nginx依赖于pcre、zlib、openssl,在编译前配置时如果有问题
可以使用yum方式安装三个包(pcre-devel、zlib-devel、openssl-devel)

从Nginx官网下载Nginx源码包
wget http://nginx.org/download/nginx-1.12.2.tar.gz

解压Nginx源码包到/root/nginx,并查看Nginx源文件结构
tar -xzvf nginx-1.12.2.tar.gz

在/root/nginx目录进行编译前配置
cd /root/nginx*
./configure --prefix=/usr/local/nginx --with-http_ssl_module

在/root/nginx目录执行编译安装
make && make install

启动nginx
关闭防火墙
setenforce 0
systemctl stop firewalld
systemctl disable firewalld

进入到安装目录/usr/local/nginx,查看目录结构
cd /usr/local/nginx
pwd
ls

启动Nginx
/usr/local/nginx/sbin/nginx
查看Nginx进程是否启动
ps aux | grep nginx

查看Nginx占用的端口号
netstat -tlnp

使用本地主机访问虚拟机上的Nginx服务器
停止nginx
停止Nginx的三种方式
# 1. 立即停止Nginx服务
/usr/local/nginx/sbin/nginx -s stop
# 2.完成当前任务后停止
/usr/local/nginx/sbin/nginx -s quit
# 3.杀死Nginx进程
killall nginx
把nginx命令添加到环境变量
使用软连接将nginx链接到/usr/local/sbin
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
ll /usr/local/sbin/ | grep "nginx"

显示当前环境变量PATH
echo $PATH
编辑.bash_profile文件
vim ~/.bash_profile
在.bash_profile文件末尾加入以下内容
export PATH=$PATH:/usr/local/nginx/sbin

引用.bash_profile文件
source ~/.bash_profile
使用nginx命令
# 启动nginx
nginx
# 停止nginx
nginx -s quit
把nginx命令添加到系统服务
创建并编辑文件/root/service-nginx.sh
#!/bin/sh
#
# filename: service-nginx.sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
#nginx="/usr/sbin/nginx"
nginx="/usr/local/sbin/nginx"
prog=$(basename $nginx)
#NGINX_CONF_FILE="/etc/nginx/nginx.conf"
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
# END
用/root/service-nginx.sh替换/etc/init.d/nginx
mv /root/service-nginx.sh /etc/init.d/nginx
赋予可执行限权
chmod 755 /etc/init.d/nginx
执行
systemctl start nginx
源码方式安装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/connect/p/nginx-install-src.html
Linux下源码安装并配置Nginx的更多相关文章
- nginx在Centos7.5下源码安装和配置
安装nginx 安装nginx依赖包 yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim 进入目录/root/se ...
- linux下源码安装netcat
linux下源码安装netcat http://blog.chinaunix.net/uid-20783755-id-4211230.html 1,下载netcat源码,netcat-0.7.1-13 ...
- linux下源码安装软件
在linux下的很多软件都是通过源码包方式发布的,这样做对于最终用户而言,虽然相对于二进制软件包,配置和编译起来繁琐点,但是它的可移植性却好得多,针对不同的体系结构,软件开发者往往仅需发布同一份源码包 ...
- Linux 下源码安装大杂烩
本文仅以记录平常源码安装部分软件是需注意的关键点. 有时为了方便,如在 Ubuntu 系统中,采用 sudo apt-get install soft-version 来安装某一版本的软件显得更为便捷 ...
- linux下源码安装apache服务
1.搭建静态网站是,我们只需要搭建apache服务即可满足要求. 例如:如果我再客户端游览器输入地址,他会找到192.168.1.100这个服务器,然后根据端口会找到apache服务器.apache他 ...
- Linux下源码安装MySQL-5.6.25
从mysql-5.5起,mysql源码安装开始使用cmake了,因此我们得先安装cmake,配置安装目录./configure --perfix=/.....的时候和以前的会有些区别. 一.安装cma ...
- Linux下源码安装方式安装MySQL
1.下载安装包:https://downloads.mysql.com/archives/community/ 2.安装开发工具和安装包 因为要把源码编译成二进制数据,所以必须要有编译器和解释器 g ...
- Linux下源码安装JDK7
安装说明 安装环境:Red Hat Enterprise Linux7.1安装方式:源码安装 软件:jdk-7u80-linux-x64.gz 安装 #首先查看系统原有JDK信息 rpm -qa | ...
- linux下源码安装rabbitMq
一.安装erlang前期环境安装1.利用yum安装erlang编译所依赖的环境 yum -y install make gcc gcc-c++ kernel-devel m4ncurses-devel ...
随机推荐
- selenium对百度进行登录注销
#百度登录退出demo import time from selenium import webdriver from selenium.webdriver.common.action_chains ...
- buaaoo_second_assignment
远瞧忽忽悠悠,近瞧飘飘摇摇,走近点留神看,原来是,电梯被测爆 (一)基于多线程的设计分析 (1)傻瓜电梯 第一次电梯本来想用多线程去写,但是当时对于线程的理解还不够充分(甚至把人当成了线程去找电梯,然 ...
- [原创]windows 部署SS server 出现的错误.
安装过程: .Download and install Python MSI installer in 64bit Windows. .During installation you should i ...
- Docker 学习6 Docker存储卷
一.什么是存储卷 二.为什么要用到数据卷 三.数据卷是怎么被管理的 四.存储卷种类 五.在容器中使用存储卷 1.只声明容器路径 [root@localhost docker]# docker run ...
- main方法启动spring
main方式读取spring配置.main方法启动spring/ 有时候只想写一下简单的测试用一下. 新建一个maven项目 依赖pom <?xml version="1.0" ...
- Linux操作系统log日志日志分别指什么
Linux操作系统log日志日志分别指什么 2019-04-20 20:41:05 一.一般的日志 /var/log/messages —包括整体系统信息,其中也包含系统启动期间的日志.此外,m ...
- jquery.string.js
/** * jquery.string - Prototype string functions for jQuery * version: 1.1.0 * (c) 2008-2011 David E ...
- 什么是nrm
什么是nrm nrm 是一个 npm 源管理器,允许你快速地在 npm 源间切换. 安装nrm 在命令行执行命令,npm install -g nrm,全局安装nrm. 使用 执行命令nrm ls查看 ...
- 使用smb映射到本地时 访问权限,请联系管理员错误
1 这个原因是违反了 SELinux安全策略导致的 2 解决办法 关闭SELinux 先使用getenforce ,如果是Enforcing 就使用setenforce 0 关闭
- ios12版本以上键盘唤起后,收回页面不回滚问题
最近提测后,发现ios升级到12版本之后,引发了调用确认框的组件之后按钮失效问题. 然后开始了升级复现bug的各种操作,最后发现是完成后键盘收起后,页面没有回滚,因为页面整体被推上了一定高度,导致错位 ...