前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >Nginx常用模块有哪些?一次装完太爽了

Nginx常用模块有哪些?一次装完太爽了

作者头像
大风写全栈
发布2024-12-19 21:22:16
发布2024-12-19 21:22:16
16300
代码可运行
举报
文章被收录于专栏:锤子代码锤子代码
运行总次数:0
代码可运行

忘记装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 <<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:

代码语言:javascript
代码运行次数:0
复制
systemctl daemon-reload

设置开机启动Nginx:

代码语言:javascript
代码运行次数:0
复制
systemctl enable nginx

启动Nginx:

代码语言:javascript
代码运行次数:0
复制
systemctl start nginx

检查Nginx运行状态:

代码语言:javascript
代码运行次数:0
复制
systemctl status nginx

大功告成!~

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-12-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 锤子代码 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档