Linux - nginx安装 含支持TCP、SSL
Nginx安装 (以1.16.1为例) 贴心之作
一:安装依赖:
1. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install gcc-c++
2. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:
yum install -y pcre pcre-devel
3. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
yum install -y zlib zlib-devel
4. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yum install -y openssl openssl-devel
二:Nginx下载
wget http://nginx.org/download/nginx-1.16.1.tar.gz
三:解压
依然是直接执行命令
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
四:安装
# 安装https支持:--with-http_ssl_module
# 安装tcp支持:--with-stream
# 执行 添加https 和 tcp支持
./configure --with-http_ssl_module --with-stream
# 编译安装
make
make install
查找安装路径:
whereis nginx
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"
至此已安装完成。
为了在任何目录都可以操作nginx,配置全局操作查看下面步骤。
五:配置系统全局路径
#运行
vim /etc/profile
#在最后面加入:
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
#保存
#然后运行:让配置文件生效
source /etc/profile
# 检验是否成功,输入下面命令是否有版本号输出
nginx -v
六:启动、停止nginx命令
#所有位置都可以执行
启动Nginx:start nginx
快速停止或关闭Nginx:nginx -s stop
正常停止或关闭Nginx:nginx -s quit
配置文件修改重装载命令:nginx -s reload
如有帮助留下你的小赞!!!
有什么不合适的地方敬请留言!!!