Ubuntu编译安装Nginx(转)

admin3年前复制粘贴474


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





相关文章

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

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

git 简单常用命令(持续添加...)

#创建一个服务器仓库 git --bare init myRepository.git #克隆一个仓库到本地 git clone git@服...

frp配置(转)

Frp服务的搭建搭建frp很简单,关键的步骤只有三步:1、获取frp文件;2、设置frp配置文件,3、启动frp服务。(注意frp搭建的的这三步是分为客户端和服务端的,但是操作基本是一致的。)本教程f...

php配置文件说明(转)

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

Python依赖安装

一、依赖清单导出和包下载在项目根目录执行 #仅生成当前项目依赖清单文件(和freeze命令 二选一) requirements.txt pipreqs ./&nb...

windows配置PAC自动脚本(转)

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

发表评论    

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