linux安装nginx

下载

http://nginx.org/

下载:

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

解压:

1
tar -xvzf nginx-1.20.2.tar.gz

安装

linux系统需要安装的组件:gcc、 openssl-devel、 pcre-devel、 zlib-devel

可以使用yum查看是否已经安装:

1
yum list installed | grep openssl-devel

安装组件:

1
yum install gcc openssl-devel pcre-devel zlib-devel

配置:

1
2
cd nginx-1.20.2
./configure --prefix=/usr/local/nginx/

显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library

nginx path prefix: "/usr/local/nginx/"
nginx binary file: "/usr/local/nginx//sbin/nginx"
nginx modules path: "/usr/local/nginx//modules"
nginx configuration prefix: "/usr/local/nginx//conf"
nginx configuration file: "/usr/local/nginx//conf/nginx.conf"
nginx pid file: "/usr/local/nginx//logs/nginx.pid"
nginx error log file: "/usr/local/nginx//logs/error.log"
nginx http access log file: "/usr/local/nginx//logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

查看内置模块:

1
cat nginx-1.20.2/auto/options | grep YES

可以直接用–with-模块名安装。

第三方模块安装:

下载第三方模块到服务器上比如:/usr/local/fastdfs-nginx-module-1.22/src/

编译时加入–add-module:

1
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-1.22/src/

编译安装:

1
make && make install

如果只是添加模块只需要make,然后再手动把nginx执行文件覆盖到原来的执行文件。**(需要停服)**

1
cp objs/nginx /usr/local/nginx/sbin/nginx

启动

1
/usr/local/nginx/sbin/nginx -?

显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
nginx version: nginx/1.20.2
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-g directives]

Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx//)
-e filename : set error log file (default: logs/error.log)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file

启动:

1
/usr/local/nginx/sbin/nginx

查看进程:

1
ps -ef | grep nginx

检查配置文件:

1
/usr/local/nginx/sbin/nginx -t

重新加载配置:

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

停止:

1
/usr/local/nginx/sbin/nginx -s stop

linux安装nginx
http://hanqichuan.com/2022/05/07/linux/linux安装nginx/
作者
韩启川
发布于
2022年5月7日
许可协议