Ubuntu编译安装Nginx(转)

admin3年前复制粘贴413


1、依赖安装

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libtool
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libssl-dev


2、nginx源码包 (也可自行去 http://nginx.org/download/ 找想要的包)

wget http://nginx.org/download/nginx-1.21.6.tar.gz
tar -zxvf nginx-1.21.6.tar.gz
cd ./nginx-1.21.6


3、增加nginx用户(编译参数中 指定了以名为nginx的用户运行,所以先增加一个用户,不然会报错)

groupadd  nginx
useradd -M -s /sbin/nologin -g nginx nginx


4、编译安装 

./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_v2_module \
--with-http_sub_module \
--with-http_mp4_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre --with-stream \
--with-stream_ssl_module \
--with-stream_realip_module


make && make install


5、创建服务文件

#创建服务文件
vim /lib/systemd/system/nginx.service


#写入以下内容
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.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


6、加入开机启动

systemctl enable nginx


7、基本操作

#创建软链接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/   
#测试配置
nginx -t
#以默认配置运行
nginx 或 systemctl start nginx
#平滑重启
nginx -s reload

#重启服务
systemctl restart nginx

#停止服务
systemctl stop nginx





相关文章

screen几个命令

参数说明-A  将所有的视窗都调整为目前终端机的大小。-d <作业名称>  将指定的screen作业离线。-h <行数>  指定视窗的缓冲区行数。-m  即使目前已在作业中的s...

花生壳和pubyun(原3322)在linux下快速解析

一、花生壳通过设置路由器自定义地址(免费版已经无法解析)http://用户名:密码@/ddns.oray.com/ph/update?&hostname=域名/ curl -fsS...

Ubnt路由器设置ssl证书(转)

根据 Ubnt路由器更换HTTPS证书文件 的说明,更换证书,大部分情况下我们再CA机构拿到的证书一般是 xxx.pem xxx.key 两个文件(nginx)版,或者apache版 xxx.key...

nginx配置详解(转)

nginx配置文件结构...              #全...

mysql导出指定时间段binlog(需要已经开启binlog)

mysqlbinlog --no-defaults --start-datetime="2018-09-06 13:45:00" --sto...

php配置文件说明(转)

一、核心目录和文件1 php核心配置文件 /etc/php.ini php 2 php扩展配置文件目录 /etc/php.d/ 3 php-fpm进程服...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。