nginx环境搭建

1、下载nginx

2、解压并安装

tar zxvf nginx-1.7.8.tar.gz  --解压
mv nginx-1.7.8  nginx  --更改文件名
useradd -s /sbin/nologin -M nginx  --创建nginx用户 
yum install -y gcc openssl-devel pcre-devel zlib-devel libxml2-devel bzip2-devel wget   --安装依赖库
cd nginx
./configure  --prefix=/usr/local/nginx  --error-log-path=/var/log/nginx/error.log   --http-log-path=/var/log/nginx/access.log   --user=nginx   --group=nginx   --with-http_ssl_module   --with-http_stub_status_module   --with-http_gzip_static_module   --with-pcre   --with-stream  
make && make install

 

3、验证Nginx配置文件是否正确

  

4、启动和停止

  cd /usr/local/nginx/sbin

  启动:./nginx

  重启:nginx -s reload

  停止:nginx -s stop

  强制停止:pkill -9 nginx

5、可能出现的问题

  nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
  [root@xiaoxitest sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  [root@xiaoxitest sbin]# ./nginx -s reload  #重启OK

6、访问验证

  

 7、增加service启动

vim /etc/init.d/nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
 
# nginx - this script starts and stops the nginx daemon
 
# 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/local/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    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
killall -9 nginx
}
 
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

  

service nginx start  启动

service nginx stop  关闭

service nginx restart  重启

posted @   小郗测试  阅读(307)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示