news 2026/5/19 17:23:14

离线安装 Nginx,docker换源,apt换源

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
离线安装 Nginx,docker换源,apt换源

离线安装 Nginx

  • 参考来源
  • 一、下载
  • 二、编译参数
  • 三、配置环境变量
  • 四、创建nginx服务
  • 五、启动及验证
  • 六、编译参数
  • 其他、
    • 1、下载功能
    • 2、当图片服务器

参考来源

1、离线安装 Nginx
2、Nginx服务配合负载均衡做代理网关
3、nginx好用的模块

一、下载

Nginx官网:Nginx官网

cd/workspacetar-zxvfnginx-1.22.1.tar.gzmvnginx-1.22.1 nginxcdnginx ./configure --with-http_mp4_module --with-http_flv_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_gunzip_module --with-file-aiosudomake&&makeinstall

二、编译参数

三、配置环境变量

vi/etc/profile

内容如下:

exportNGINX_HOME=/usr/local/nginxexportPATH=$PATH:$NGINX_HOME/sbin

生效:

source/etc/profile

四、创建nginx服务

sudovi/lib/systemd/system/nginx.service

内容如下:

[Unit]Description=nginxserviceAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx-sreloadExecStop=/usr/local/nginx/sbin/nginx-squitPrivateTmp=true[Third_party]WantedBy=multi-user.target

五、启动及验证

# 启动nginxsystemctl start nginx# 查看nginx状态systemctl status nginx# 设置开机自启动systemctlenablenginx# 验证curlhttp://localhost

源码启动

nginx-c/usr/local/nginx/conf/nginx.conf

重加载

nginx-sreload-c/usr/local/nginx/conf/nginx.conf#docker方式重加载dockerexec-itXXX nginx-sreload

六、编译参数

参考来源:
1、https://www.cnblogs.com/linyouyi/p/11502282.html
2、https://comate.baidu.com/zh/page/2kstn86weoh
3、https://vip.kingdee.com/knowledge/464722953813409280?productLineId=29&isKnowledge=2&lang=zh-CN

./configure 脚本后面可以跟许多参数来定制 Nginx 的配置,详情看官网:https://nginx.org/en/docs/configure.html
部分常用参数配置:

–prefix=PATH指定 Nginx 安装目录,默认为 /usr/local/nginx –sbin-path=PATH指定 Nginx 可执行文件的路径,默认为 PREFIX/sbin/nginx –conf-path=PATH指定 Nginx 配置文件的路径,默认为 PREFIX/conf/nginx.conf –error-log-path=PATH指定错误日志文件的路径,默认为 PREFIX/logs/error.log –http-log-path=PATH指定访问日志文件的路径,默认为 PREFIX/logs/access.log –pid-path=PATH指定 PID 文件的路径,默认为 PREFIX/logs/nginx.pid –lock-path=PATH指定锁文件的路径,默认为 PREFIX/logs/nginx.lock –user=USER指定 Nginx 工作进程运行的用户,默认为 nobody –group=GROUP 指定 Nginx 工作进程运行的用户组,默认为 nobody –with-http_ssl_module 启用 SSL 支持 –with-http_v2_module 启用 HTTP/2 支持(需要 OpenSSL1.0.2 或更高版本) –with-http_gzip_static_module 启用gzip静态文件压缩支持 –with-http_realip_module 启用获取客户端真实 IP 地址的支持 –with-http_stub_status_module 启用状态页面模块,用于监控 Nginx 状态 –with-http_sub_module 启用响应内容替换模块 –with-http_dav_module 启用 WebDAV 支持 –with-http_flv_module 启用 FLV 视频流支持 –with-http_mp4_module 启用 MP4 视频流支持 –with-http_gunzip_module 启用 gunzip 模块,用于解压gzip压缩的内容 –with-http_auth_request_module 启用基于子请求的认证模块 –with-http_random_index_module 启用随机索引模块 –with-http_secure_link_module 启用安全链接模块 –with-http_degradation_module 启用降级模块 –with-http_perl_module 启用 Perl 模块(需要 Perl5.6.1 或更高版本) –with-mail 启用邮件代理模块 –with-mail_ssl_module 启用邮件代理模块的 SSL 支持 –with-stream 启用流媒体模块 –with-stream_ssl_module 启用流媒体模块的 SSL 支持 –with-stream_realip_module 启用流媒体模块的获取客户端真实 IP 地址支持 –with-stream_geoip_module 启用流媒体模块的 GeoIP 支持(需要 GeoIP 库) –with-http_geoip_module 启用 HTTP 模块的 GeoIP 支持(需要 GeoIP 库) –with-file-aio 启用文件异步 I/O 支持 –with-threads 启用线程池支持 –with-compat 启用兼容模式,允许使用第三方模块 –without-http 不编译 HTTP 模块 –without-http-cache 不编译 HTTP 缓存模块 –without-mail_pop3_module 不编译 POP3 邮件协议模块 –without-mail_imap_module 不编译 IMAP 邮件协议模块 –without-mail_smtp_module 不编译 SMTP 邮件协议模块

1、Nginx被动监控检查

proxy_next_upstream#已内置

完整示例:

upstream cluster{server172.16.0.23:80max_fails=1fail_timeout=10s;server172.16.0.24:80max_fails=1fail_timeout=10s;# max_fails=1和fail_timeout=10s 表示在单位周期为10s钟内,中达到1次连接失败,那么接将把节点标记为不可用,并等待下一个周期(同样时常为fail_timeout)再一次去请求,判断是否连接是否成功。# fail_timeout为10s,max_fails为1次。}server{listen80;server_name xxxxxxx.com;location /{proxy_pass http://cluster;}}

2、Nginx主动健康检查
主动地健康检查,nignx定时主动地去ping后端的服务列表,当发现某服务出现异常时,把该服务从健康列表中移除,当发现某服务恢复时,又能够将该服务加回健康列表中。

--nginx_upstream_check_module

完整配置示例:

http{upstream backend{server192.168.0.1:80;server192.168.0.2:80;checkinterval=3000rise=2fall=3timeout=1000type=http;check_http_send"HEAD /health HTTP/1.0\r\n\r\n";check_http_expect_alive http_2xx http_3xx;}server{location /{proxy_pass http://backend;}location /status{check_status;access_log off;}}}

下载模块
old

gitclone https://github.com/yaoweibin/nginx_upstream_check_module.git

new

gitclone https://github.com/mofantor/nginx_upstream_check_module.gitwgethttp://nginx.org/download/nginx-1.30.0.tar.gztar-xzvfnginx-1.30.0.tar.gzcdnginx-1.30.0/# 编译安装patch-p1<../nginx_upstream_check_module/check_1.30.0+.patch ./configure --add-module=../nginx_upstream_check_modulemakesudomakeinstall

状态监控
通过check_status指令可查看健康状态(支持JSON/HTML格式):
访问http://your-server/status获取结果。

location /status{check_status json;#allow 192.168.0.0/16;#deny all;}

3、这个模块能够获取Nginx自上次启动以来的工作状态(状态统计)

--with-http_stub_status_module

示例

location /nginx_status{stub_status on;access_log off;#访问控制#allow 192.168.110.132;;#deny all;#认证#auth_basic "close site";#auth_basic_user_file /usr/local/nginx/conf/htpasswd;}

认证设置密码
htpasswd -c /usr/local/nginx/conf/htpasswd admin

访问:http://localhost/nginx_status

会看到这样的信息:

Active connections:291server accepts handled requests166309481663094831070465Reading:6Writing:179Waiting:106

Active connections:当前的活跃连接数
accepts:服务器已接受的连接数
handled:服务器已处理的连接数:
requests:服务器已处理的请求
Reading – Nginx 读取的请求头次数为 6;
Writting – Nginx 读取请求体、处理请求并发送响应给客户端的次数为 179;
Waiting – 当前活动的长连接数:106。


其他、

1、下载功能

在html目录下创建一个目录download,可以放各种文件,还要存在一个index.html;
location中添加autoindex on;

server{listen18010;server_name localhost;#access_log logs/host.access.log main;location /images/{alias/usr/local/nginx/html/images/;#root /usr/local/nginx/html;# 和alias类似index index.html index.htm;autoindex on;#auth_basic "close site";auth_basic_user_file /usr/local/nginx/conf/htpasswd;auth_basic always;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page500502503504/50x.html;location=/50x.html{root html;}}

2、当图片服务器

在html目录中创建一个目录images,可以放图片,访问http://localhost:80/imgaes/xxx.jpg

server{listen8010;server_name localhost;#access_log logs/host.access.log main;location /{alias/usr/local/nginx/html/images/;index index.html index.htm;autoindex on;#加这个可以有下载的感觉}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page500502503504/50x.html;location=/50x.html{root html;}}

1、Linux系统版本查询
2、Debian/Ubuntu系统apt-get指定软件源配置指南

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/19 17:16:03

QEMU理解与分析系列(5):RISCV虚拟版卡初始化

文章目录 1、QOM简介 `register_module_init` 的实现 Machine 类型注册 Machine 类定义 MachineClass 结构体定义 MachineState 结构体定义 virt 机器初始化流程 自定义设备初始化 1、QOM简介 QEMU Object Model (QOM) 是 QEMU 中的一种对象系统,用于实现 QEMU 设备模型和设备…

作者头像 李华
网站建设 2026/5/19 17:15:05

如何轻松解密科学文库PDF:完整实用的3步永久解密指南

如何轻松解密科学文库PDF&#xff1a;完整实用的3步永久解密指南 【免费下载链接】ScienceDecrypting 破解CAJViewer带有效期的文档&#xff0c;支持破解科学文库、标准全文数据库下载的文档。无损破解&#xff0c;保留文字和目录&#xff0c;解除有效期限制。 项目地址: htt…

作者头像 李华
网站建设 2026/5/19 17:03:05

解锁Nintendo Switch游戏备份的终极指南:nxdumptool完全攻略

解锁Nintendo Switch游戏备份的终极指南&#xff1a;nxdumptool完全攻略 【免费下载链接】nxdumptool Generates XCI/NSP/HFS0/ExeFS/RomFS/Certificate/Ticket dumps from Nintendo Switch gamecards and installed SD/eMMC titles. 项目地址: https://gitcode.com/gh_mirro…

作者头像 李华