nginx第一天

nginx 介绍

常见的webserver(排行https://news.netcraft.com/archives/2018/)

  •      老牌:httpd(早期叫Apache),开源,市场份额最高

  •      微软:iis

  •      轻量:lighttpd,性能高,低耗能,功能欠缺

nginx诞生

  •      2004年10月发布,俄国人igor sysoev 开发,ranbler.ru

nginx官网、版本

  •      nginx.org    当前最高版本1.17

  •      国内分支tengine(http://tengine.taobao.org),可以考虑使用

nginx功能介绍

  •     http服务、反向代理、负载均衡、邮件代理、缓存功能、缓存加速、ssl、flv/mp4流媒体


nginx 通过yum安装

安装yum源方式安装

1、安装扩展源直接安装

yum -y install epel-release

yum -y install nginx

2、添加nginx.repo方式安装

vi /etc/yum.repo.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

  • 源网络地址:https://coding.net/u/aminglinux/p/nginx/git/blob/master/2z/nginx.repo
  • 查看nginx版本 :yum list  |grep nginx 

  • 安装:yum -y install nginx

管理nginx

systemctl start/stop/restart/reload nginx        启动,停止,重启,重新加载nginx

测试:浏览器访问或者curl访问

  • 检查服务进程:ps -aux|grep nginx
  • 检查端口监听:netstat -antup |grep 80
  • 有防火墙,需要添加iptables -I INPUT -p tcp --dport 80 -j ACCEPT

版本查看

  • nginx -V 查看版本以及各个目录、参数

  • 访问:http://192.168.20.19


nginx 通过源码安装

下载当前稳定版1.16.1,解压

  • wget http://nginx.org/download/nginx-1.16.1.tar.gz

  • tar zxf nginx-1.16.1.tar.gz

进入解压目录,进行配置,编译,安装

  • cd nginx-1.16.1

  • ./configure  --prefix=/usr/local/nginx

  • make  && make install

启动,停止,重载,检测配置文件语法是否有错误

  • /usr/local/nginx/sbin/nginx

  • pkill nginx 或者killall nginx

  • /usr/local/nginx/sbin/nginx -s reload

  • /usr/local/nginx/sbin/nginx -t

服务脚本管理

https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx

vi  /etc/init.d/nginx

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"

start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}

stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}

reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}

restart()
{
stop
start
}

configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}

case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac

exit $RETVAL

原文地址:https://www.cnblogs.com/jessi-w/p/12051237.html