Ubuntu编译安装Nginx(转)

admin2年前复制粘贴296


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





相关文章

zip和unzip基本命令(转)

一、基本参数1、zip命令的常用参数-d:从压缩文件内删除指定的文件-D:压缩文件内不建立目录名称-g:将文件压缩后附加在已有的压缩文件之后,而非另行建立新的压缩文件-m:将文件压缩并加入压缩文件后,...

windows配置PAC自动脚本(转)

PAC文件内容示例function FindProxyForURL(url, host) { var proxy1 = "P...

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

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

js图片压缩(转)

var compressImage = {     compressByFile: function(file,&...

nginx配置详解(转)

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

docker常用命令(持续添加...)

#搜索镜像 php可替换为其他 docker search php #拉取php镜像 docker pull php #拉取指定版本镜...

发表评论    

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