Ubuntu 系统下安装 Nginx
一、Nginx是什么
是一个高性能的 HTTP 和反向代理 web 服务器,同时也提供了 IMAP/POP3/SMTP 服务。
是一款轻量级的 Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强。
二、Ubuntu 系统下安装 Nginx
1、安装包下载
地址:Index of /download/
2、上传服务器并解压缩
tar -zxvf nginx-1.16.1.tar.gz
3、依赖配置安装
sudo apt install gcc make libpcre3-dev zlib1g-dev openssl libssl-dev
4、生成编译脚本
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-cc-opt="-Wno-error -Wno-deprecated-declarations"
5、编译
make
6、开始安装
make install
7、设置为随机自启动
7.1、创建 nginx.service 文件,将以下内容粘贴到文件中
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
7.2、将 nginx.service 放入 /etc/systemd/system/ 下,并授权
chmod 777 nginx.service
7.3、配置重新加载
systemctl daemon-reload
7.4、开启Nginx随机自启服务
systemctl enable nginx.service
7.5、 启动Nginx
systemctl start nginx.service
7.6、查看服务状态
systemctl status nginx.service