Ubuntu 系统下安装 Nginx

目录

一、Nginx是什么

[?二、Ubuntu 系统下安装 Nginx](#?二、Ubuntu 系统下安装 Nginx)

1、安装包下载

2、上传服务器并解压缩

3、依赖配置安装

4、生成编译脚本

?5、编译

6、开始安装

7、设置为随机自启动

[7.1、创建 nginx.service 文件,将以下内容粘贴到文件中](#7.1、创建 nginx.service 文件,将以下内容粘贴到文件中)

[7.2、将 nginx.service 放入 /etc/systemd/system/ 下,并授权](#7.2、将 nginx.service 放入 /etc/systemd/system/ 下,并授权)

7.3、配置重新加载

7.4、开启Nginx随机自启服务

[7.5、 启动Nginx](#7.5、 启动Nginx)

7.6、查看服务状态?


一、Nginx是什么

  • 是一个高性能的 HTTP 和反向代理 web 服务器,同时也提供了 IMAP/POP3/SMTP 服务。
  • 是一款轻量级的 Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强。

二、Ubuntu 系统下安装 Nginx

1、安装包下载

地址:https://nginx.org/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

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

若发现以下错误,这是因为80端口已经被其他进行占用导致Nginx无法绑定到80端口上,可尝试查询端口占用进程并终止该进程。


相关推荐
jay丿4 小时前
django数据查询
数据库·django·sqlite
ChinaRainbowSea4 小时前
8. Nginx 配合 + Keepalived 搭建高可用集群
java·运维·服务器·后端·nginx
若云止水4 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_list_init
nginx·ubuntu·list
JANGHIGH4 小时前
Ubuntu 20.04下配置VSCode以支持OpenCV库开发
vscode·opencv·ubuntu
猫头鹰~4 小时前
Ubuntu20.04安装Redis
java·数据库·redis
若云止水4 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(5)
网络·nginx·ubuntu
engchina4 小时前
使用Docker搭建Oracle Database 23ai Free并扩展MAX_STRING_SIZE的完整指南
数据库·docker·oracle
Suckerbin4 小时前
SQL-labs less9-12 闯关记录
数据库·学习·安全·网络安全·oracle
04Koi.4 小时前
Redis--单线程模型
数据库·redis·缓存