[Linux]Nginx安装

Linux中Nginx安装

1. 下载Nginx的tar.gz源码版本,解压并复制到安装的目录下

1
2
tar -zxvf nginx-file.tar.gz
cd nginx-file

2. 创建Nginx组和用户

1
2
gorupadd nginx
useradd -M -s /sbin/nologin nginx -g nginx

3. 查看Nginx编译参数

1
./configure --help

4. 执行编译检查

1
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

常用模块说明:

  • with-http_stub_status_module:开启Nginx状态检测
  • with-http_ssl_module:开启Https安全请求

若出现:

1
2
3
4
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

说明没有安装pcre-devel包,执行yum install pcre-devel进行安装

若出现:

1
2
3
4
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

说明没有安装openssl-devel包,执行yum install openssl-devel进行安装

所有检查成功后,一般会出现待会安装的一些信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ 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"

5. 执行编译

1
make install

6. 执行安装,其实就是复制到目标目录

1
make

(•̀ᴗ•́)و ̑̑

Share