编程技术分享平台

网站首页 > 技术教程 正文

uos编译安装nginx(编译安装nginx启动命令)

xnh888 2024-09-09 09:51:28 技术教程 34 ℃ 0 评论

一、安装依赖

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

}

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表