忘记装SSL模块的尴尬
前几年,有个老项目需要上SSL证书。
一看Nginx,竟然没安装SSL模块。
直接傻眼。各种找教程,重新安装SSL模块。
说起Nginx的模块,除了SSL之外还有httpv2,mail,stream等等。
stream模块可能很多人没接触过,主要用来接收数据流,之前有个项目用这个模块接收硬件设备上报的数据(tcp)。
当时Nginx的作用依然是反向代理,前面Nginx,后面是Java。
最近刚好安装环境,顺手记录一下Nginx安装流程。
操作系统主要针对Centos,其它系统也是类似的。
安装流程(亲测可用)
更新系统包
yum update -y
安装必要的依赖
yum install -y gcc pcre-devel zlib-devel openssl-devel make wget
下载Nginx安装包:
https://nginx.org/en/download.html
下面假设版本为1.27.3(当前最新版):
tar -zxvf nginx-1.27.3.tar.gz
cd nginx-1.27.3
配置编译选项(常用模块):
Nginx安装路径: /usr/local/nginx
配置文件路径: /usr/local/nginx/conf/nginx.conf
HTML页面路径:/usr/local/nginx/html
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-http_slice_module \
--with-compat
编译并安装:
make && make install
创建systemd服务(方便管理):
cat <<EOF | sudo tee /etc/systemd/system/nginx.service
[Unit]
Description=Nginx Server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
重新加载systemd:
systemctl daemon-reload
设置开机启动Nginx:
systemctl enable nginx
启动Nginx:
systemctl start nginx
检查Nginx运行状态:
systemctl status nginx
大功告成!~