nginx
1.实验环境
- 环境说明
| 主机名 | IP地址 | 角色 | 系统版本 |
|---|---|---|---|
| nginx-server | 192.168.100.114 | nginx服务 | red-hat7 |
- 关闭防火墙和selinux
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# setenforce 0
2.下载nginx
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
[[email protected] src]# tar xf nginx-1.14.0.tar.gz
[[email protected] src]# ls
debug kernels nginx-1.14.0 nginx-1.14.0.tar.gz
3.安装依赖环境
[[email protected] src]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc
[[email protected] src]# yum -y groups mark install 'Development Tools'
4.创建nginx用户
[[email protected] src]# groupadd -r nginx
[[email protected] src]# useradd -r -M -s /sbin/nologin -g nginx nginx
5.创建日志存放路径
[[email protected] src]# mkdir -p /var/log/nginx
[[email protected] src]# chown -R nginx.nginx /var/log/nginx
6.编译安装
[[email protected] src]# cd nginx-1.14.0/
[[email protected] nginx-1.14.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[[email protected] nginx-1.14.0]# make && make install
7.安装后配置
[[email protected] ~]# echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
[[email protected] ~]# . /etc/profile.d/nginx.sh
[[email protected] ~]# which nginx
/usr/local/nginx/sbin/nginx
//服务控制方式-t //检查配置文件语法-v //输出nginx版本-c //指定配置文件路径-s//发送服务控制信号 可选{quit|stop|reopen|reload}
8.启动服务
[[email protected] ~]# nginx
[[email protected] ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
9.测试
- 编写启动脚本
[[email protected] ~]# cd /etc/init.d/
[[email protected] init.d]# cat nginx
#!/bin/bash
# chkconfig: 2345 10 20
#description:nginx
nginx=/usr/local/nginx/sbin/nginx
PID=/usr/local/nginx/logs/nginx.pid
//第一行表示脚本在chkconfig管理中启动的相关参数,2345表示默认启动级别,10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低
//第二行是脚本描述信息
case "$1" in
start)
$nginx
;;
stop)
kill -s QUIT $(cat $PID)
;;
restart)
$0 stop && $0 start
;;
reload)
kill -s HUP $(cat $PID)
;;
*)
echo "Usage:$0 {start|stop|restart|reload}"
exit 1
esac
[[email protected] init.d]# chmod +x nginx
[[email protected] init.d]# chkconfig --add nginx
- 测试
[[email protected] init.d]# service nginx stop
[[email protected] init.d]# service nginx start