忘记装SSL模块的尴尬
前几年,有个老项目需要上SSL证书。
一看Nginx,竟然没安装SSL模块。
直接傻眼。各种找教程,重新安装SSL模块。
说起Nginx的模块,除了SSL之外还有httpv2,mail,stream等等。
stream模块可能很多人没接触过,主要用来接收数据流,之前有个项目用这个模块接收硬件设备上报的数据(tcp)。
当时Nginx的作用依然是反向代理,前面Nginx,后面是Java。
最近刚好安装环境,顺手记录一下Nginx安装流程。
操作系统主要针对Centos,其它系统也是类似的。
安装流程(亲测可用)
更新系统包
代码语言:javascript代码运行次数:0运行复制yum update -y安装必要的依赖
代码语言:javascript代码运行次数:0运行复制yum install -y gcc pcre-devel zlib-devel openssl-devel make wget下载Nginx安装包:
https://nginx.org/en/download.html
下面假设版本为1.27.3(当前最新版):
代码语言:javascript代码运行次数:0运行复制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
代码语言:javascript代码运行次数:0运行复制./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编译并安装:
代码语言:javascript代码运行次数:0运行复制make && make install创建systemd服务(方便管理):
代码语言:javascript代码运行次数:0运行复制cat < [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: 代码语言:javascript代码运行次数:0运行复制systemctl daemon-reload设置开机启动Nginx: 代码语言:javascript代码运行次数:0运行复制systemctl enable nginx启动Nginx: 代码语言:javascript代码运行次数:0运行复制systemctl start nginx检查Nginx运行状态: 代码语言:javascript代码运行次数:0运行复制systemctl status nginx大功告成!~