CentOS7下安装nginx及相关配置

官网下载

https://nginx.org/

1
wget https://nginx.org/download/nginx-1.20.2.tar.gz

解压并安装

依赖包的安装yum -y install gcc-c++ openssl-devel pcre pcre-devel make

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@localhost ~]# tar xvf nginx-1.20.2.tar.gz
[root@localhost ~]# cd nginx-1.20.2
[root@localhost nginx-1.20.2]# ll
total 792
drwxr-xr-x. 6 1001 1001 4096 Apr 20 15:07 auto
-rw-r--r--. 1 1001 1001 312251 Nov 16 22:44 CHANGES
-rw-r--r--. 1 1001 1001 476577 Nov 16 22:44 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Apr 20 15:07 conf
-rwxr-xr-x. 1 1001 1001 2590 Nov 16 22:44 configure
drwxr-xr-x. 4 1001 1001 72 Apr 20 15:07 contrib
drwxr-xr-x. 2 1001 1001 40 Apr 20 15:07 html
-rw-r--r--. 1 1001 1001 1397 Nov 16 22:44 LICENSE
drwxr-xr-x. 2 1001 1001 21 Apr 20 15:07 man
-rw-r--r--. 1 1001 1001 49 Nov 16 22:44 README
drwxr-xr-x. 9 1001 1001 91 Apr 20 15:07 src
[root@localhost nginx-1.20.2]# ./configure --prefix=/home/nginx
[root@localhost nginx-1.20.2]# make
[root@localhost nginx-1.20.2]# make install

运行

进入nginx所在目录/home/nginx

1
2
3
4
5
[root@localhost nginx]# sbin/nginx 
[root@localhost nginx]# ps -ef | grep nginx
root 20144 1 0 15:53 ? 00:00:00 nginx: master process sbin/nginx
nobody 20145 20144 0 15:53 ? 00:00:00 nginx: worker process
root 20149 3899 0 15:53 pts/0 00:00:00 grep --color=auto nginx

配置语法高亮设置

vim安装yum -y install vim

1
2
[root@localhost ~]# mkdir .vim
[root@localhost nginx-1.20.2]# cp -r contrib/vim/* ~/.vim/

日志处理

安装

https://goaccess.io/

依赖包的安装yum -y install libmaxminddb-devel ncurses-devel

1
2
3
4
5
6
$ wget --no-check-certificate https://tar.goaccess.io/goaccess-1.5.6.tar.gz
$ tar -xzvf goaccess-1.5.6.tar.gz
$ cd goaccess-1.5.6/
$ ./configure --enable-utf8 --enable-geoip=mmdb
$ make
# make install

使用

1
goaccess host.access.log -o ../html/report.html --real-time-html --time-format='%H:%M:S' --date-format='%d/%b/%Y' --log-format=COMBINED

其他

openrestry安装方法类似

官方网站:OpenResty® - Official Site

下载地址:openresty-1.19.9.1.tar.gz