Ubuntu22.04离线安装nginx

下载安装包

  • nginx
    nginx下载地址,选stable的即可,传到服务器上面,记住上传路径
    提示: 下面的openssl,zlib,pcre也可以不下载也可以,我这里是考虑到完全离线下载的情况
  • openssl
    这个是https需要弄得,如果生产环境不是https那可以不用装
    openssl

这个下载需要科学上网

  • zlib
    zlib
    这个是支持gzip压缩的模块
  • pcre

这个是正则表达式模块

pcre链接


我待会放一个网盘链接,下载一下就行百度网盘链接

上传到服务器当中,记住路径,我这里就上传到/usr/software/

安装gcc相关

shell 复制代码
apt install gcc build-essential make

编译nginx

进入nginx安装目录,应该是如图片所示

如果你没有下载openssl,pcre,zlib的话,执行下面的

shell 复制代码
./configure --prefix=/usr/software/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module # prefix后面跟的是nginx的安装目录,这里的意思就是说要把nginx安装到/usr/software/nginx下面
sudo make && make install

下载了pcre,openssl,zlib就执行下面的即可

shell 复制代码
./configure --prefix=/usr/software/nginx --with-http_ssl_module --with-openssl=../openssl --with-pcre=../pcre --with-zlib=../zlib # --prefix是指定安装目录的,即把nginx安装到/usr/software/nginx当中
sudo make && make install

这个过程要等一会儿,我等了4分钟

shell 复制代码
cd nginx
cd sbin
./nginx 
# 打开浏览器,在地址栏输入localhost,看到一个欢迎页面就行
# 若是命令行的话执行下面的语句
curl localhost

curl localhost的结果是

html 复制代码
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

就行了

交给systemd托管

vim /usr/lib/systemd/system/nginx.service

输入以下内容(内容中的路径需要改成你自己的)

shell 复制代码
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/software/nginx/logs/nginx.pid
ExecStartPre=/usr/software/nginx/sbin/nginx -t -c /usr/software/nginx/conf/nginx.conf
ExecStart=/usr/software/nginx/sbin/nginx -c /usr/software/nginx/conf/nginx.conf
ExecReload=/usr/software/nginx/sbin/nginx -s reload
ExecStop=/usr/software/nginx/sbin/nginx -s stop
ExecQuit=/usr/software/nginx/sbin/nginx -s quit # 
PrivateTmp=true
[Install]
wantedBy=multi-user.target
shell 复制代码
# 将服务文件复制到 /etc/systemd/system/ 目录(如果它不在那里的话)
sudo cp /usr/lib/systemd/system/nginx.service /etc/systemd/system/nginx.service

# 重新加载 systemd 以识别新的服务文件
sudo systemctl daemon-reload

# 启动 Nginx 服务
sudo systemctl start nginx

# 检查 Nginx 服务的状态
sudo systemctl status nginx

# 如果您希望 Nginx 服务在系统启动时自动运行,可以设置它为开机自启
sudo systemctl enable nginx

报错

cp: conf/koi-win' and /usr/local/nginx/conf/koi-win' are the same file

解决办法,nginx解压后会有一个nginx-x.x.x的文件夹,这个文件夹不要删除,在nginx-x.x.x同级的文件夹中新建一个nginx文件夹即可

比如:nginx-x.x.x的路径是/usr/software/nginx-x.x.x,那么nginx文件夹的路径就是/usr/software/nginx,就行

7月 23 11:44:48 notdy nginx[101959]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

98号端口占用了

shell 复制代码
ps -ef | grep nginx 

不用记住最后一行的pid

shell 复制代码
sudo kill -9 101341 # 这个是上面图片的第一行的PID
sudo kill -9 101342 # 这个是上面图片的第一行的PID
相关推荐
Leon-Ning Liu9 小时前
Oracle数据库常用视图:dba_datapump_jobs
数据库·oracle·dba
数据库生产实战9 小时前
Oracle 19C RAC下TRUNCATE TABLE的REUSE STORAGE选项作用和风险浅析!
数据库·oracle
小白银子9 小时前
零基础从头教学Linux(Day 60)
linux·数据库·mysql·oracle
瀚高PG实验室10 小时前
数据库安全配置指导
服务器·数据库·瀚高数据库
憋问我,我也不会10 小时前
MYSQL 命令
数据库·mysql
24K老游11 小时前
postgres15 flink cdc同步测试
数据库
尽兴-11 小时前
[特殊字符] 微前端部署实战:Nginx 配置 HTTPS 与 CORS 跨域解决方案(示例版)
前端·nginx·https·跨域·cors·chrom
无泡汽水11 小时前
MySQL入门练习50题
数据库·mysql
DARLING Zero two♡11 小时前
云原生基石的试金石:基于 openEuler 部署 Docker 与 Nginx 的全景实录
nginx·docker·云原生
JIngJaneIL12 小时前
助农惠农服务平台|助农服务系统|基于SprinBoot+vue的助农服务系统(源码+数据库+文档)
java·前端·数据库·vue.js·论文·毕设·助农惠农服务平台