1 安装依赖库
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2 下载nginx
在nginx下载页面获取一个最新的稳定版本的下载链接,使用wget下载,然后解压缩
cd /usr/local
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar -zxvf nginx-1.20.2.tar.gz
3 安装nginx
- ./configure
检测系统中的环境,可以通过在 configure 后加上参数来对下一步编译进行控制,比如可以通过--prefix
指定安装路径,--with-http_ssl_module
添加ssl模块支持https,执行完会生成Makefile文件
–prefix 指定安装路径
./configure
...
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"
./configure --prefix=/usr/local/nginx20 --with-http_ssl_module
...
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx20"
nginx binary file: "/usr/local/nginx20/sbin/nginx"
nginx modules path: "/usr/local/nginx20/modules"
nginx configuration prefix: "/usr/local/nginx20/conf"
nginx configuration file: "/usr/local/nginx20/conf/nginx.conf"
nginx pid file: "/usr/local/nginx20/logs/nginx.pid"
nginx error log file: "/usr/local/nginx20/logs/error.log"
nginx http access log file: "/usr/local/nginx20/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"
- make && make install
编译并且安装,安装完会在prefix路径生成指定文件夹
make && make install
4 启动nginx
启动时可以先使用./nginx -t
检查nginx配置语法是否正确,使用./nginx
启动,./nginx -s reload
重启,./nginx -s stop
停止服务
cd nginx20/sbin
./nginx
5 其他
nginx使用的过程中缺失模块,./nginx -V
查看当前configure ,然后在当前配置基础上添加相应配置,make编译(不需要make install 安装) ,将obj
文件夹中的nginx替换掉安装路径sbin
中nginx文件。
./nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx20 --with-http_ssl_module