网站首页 > 技术教程 正文
一、安装依赖
uos d版(debian10)编译依赖包
apt -y install wget git rsync gcc openssl libssl-dev libgeoip-dev libpcre3 libpcre3-dev zlib1g-dev libgd-dev
(uos系统仓库需指定依赖包版本,apt install libfreetype6 && apt install zlib1g)
uos a版(centos8)编译依赖包
yum install wget rsync gcc openssl-devel pcre-devel gd gd-devel
二、编译安装
下载地址 http://nginx.org/en/download.html
cd /usr/local/src
wget http://nginx.org/download/nginx-1.20.2.tar.gz
# nginx 监控模块, 不需要也可以不下载
git clone git://github.com/vozlt/nginx-module-vts.git
解压
tar zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
编译 安装
--user=nginx --group=nginx指定的用户,可以是系统已有的www-data,
也可以创建系统用户nginx
useradd --system -U -d '/var/www' -s /usr/sbin/nologin -c "Nginx Web User" nginx
./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--modules-path=/usr/lib64/nginx/modules \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--user=nginx \
--group=nginx \
--with-compat \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_image_filter_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_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--add-module=/usr/local/src/nginx-module-vts # 自定义添加模块,根据自己需要是否添加
# 编译安装
make && sudo make install
# 软连接到系统path下,或者添加系统变量
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
# 也可以编译的时候指定--sbin-path=/usr/sbin/nginx,
# 编译时没有指定仅仅是为了区分手动编译和系统包安装
三、添加systemd开机启动
sudo vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
四、修改系统文件限制
sudo vim /etc/security/limits.conf
nginx soft nofile 65535
nginx hard nofile 65535
# * soft nproc 65535
# * hard nproc 65535
五、修改nginx 配置
sudo vim /etc/nginx/nginx.conf
events {
worker_connections 65535;
}
worker_rlimit_nofile 65535;
http {
server_tokens off;
.....
# 监控 自定义模块部分,根据需要添加
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
vhost_traffic_status_dump /var/log/nginx/vts.db;
}
添加nginx状态监控配置, 根据需要开启
sudo vim /etc/nginx/conf.d/default.conf
server {
# 添加zabbix系统默认状态监控
location = /basic_status {
stub_status;
allow 127.0.0.1;
deny all;
access_log off;
}
......
# 监控 自定义模块部分
location /nginx_status {
#allow 10.0.0.0/8;
allow 10.0.32.5;
allow 127.0.0.1;
deny all;
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
access_log off;
}
}
六、检查配置,开机启动
sudo nginx -t
sudo systemctl enable nginx
sudo systemctl start nginx
七、添加日志切割
sudo vim /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 nginx nginx
sharedscripts
dateext
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
猜你喜欢
- 2024-10-09 Nginx编译安装(nginx编译安装 make)
- 2024-09-09 Nginx学习之简单使用和练习(nginx怎么学)
- 2024-09-09 这套Nginx日志解决方案,真香(nginx日志400)
- 2024-09-09 基于Linux:Nginx安装包的安装与配置详解
- 2024-09-09 一文带你深入浅出读懂Nginx,理论+实战,双管齐下,手把手教会你
- 2024-09-09 跟我学Nginx(三)——Centos8安装Nginx
- 2024-09-09 Nginx 文件压缩!揭秘 nginx-09-compress,提升网站性能的终极秘籍
- 2024-09-09 Nginx源码安装并开启http2.0以及brotli压缩
- 2024-09-09 编译安装Nginx,并使用jemalloc优化内存分配
- 2024-09-09 Nginx简单使用和练习(nginx操作)
你 发表评论:
欢迎- 最近发表
-
- linux日志文件的管理、备份及日志服务器的搭建
- Linux下挂载windows的共享目录操作方法
- Linux系统中的备份文件命令(linux系统中的备份文件命令有哪些)
- 麒麟KYLINOS|通过不同方法设置用户访问文件及目录权限
- 「Linux笔记」系统目录结构(linux目录的结构及含义)
- linux中修改归属权chown命令和chgrp命令
- 工作日报 2021.10.27 Android-SEAndroid权限问题指南
- Windows和Linux环境下,修改Ollama的模型默认保存路径
- 如何强制用户在 Linux 上下次登录时更改密码?
- 如何删除Linux文件夹中除某些扩展名之外的所有文件?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)