【调试笔记-20240617-Linux- frp 结合 nginx 实现内网网站在公网发布】

调试笔记-系列文章目录

调试笔记-20240617-Linux- frp 结合 nginx 实现内网网站在公网发布



前言

本文记录在 OpenWrt-23.05 上 配置 frp 和 nginx 实现内网网站在公网发布的调试步骤。

实验使用的电脑如下:

CPU:

Intel Core i5 8265U

操作系统:

Microsoft Windows 10  Professional (x64), Version 22H2, Build 19045.4412

一、调试环境


操作系统:Windows 10 专业版

操作系统详细信息如下:

Microsoft Windows 10  Professional (x64), Version 22H2, Build 19045.4412

调试环境

  • Windows 系统已安装 QEMU 并成功运行 OpenWrt 发行版

参考【安装笔记-20240520-Windows-在 QEMU 中尝试运行 OpenWRT


调试目标

公网可访问内网配置的网站。

在这里插入图片描述


二、调试步骤

公网 IP 服务器配置 frps

手动修改的 nginx 文件中, root 命令放在了最外层,如下所示:

http {

        ...
        root /srv/nginx/dl.tanghui.fun;
        ...
        server { # dl.tanghui.fun
        	...
        }
}

uci 自动生成的配置,为了统一将其放到了 .locations 文件中,通过 include 命令包含到 server 中,如下所示:

http {

        ...
        root /www;
        ...
        server { # dl.tanghui.fun
        	...
        	include conf.d/dl.tanghui.fun.locations;
        	include conf.d/php8.locations;
        	...
        }
}

dl.tanghui.fun.locations 文件内容如下:

location / {
    root /srv/nginx/dl.tanghui.fun;
    index index.html index.php;
    try_files $uri $uri/ /index.php$is_args$args;
    if ( -d $request_filename ) {
        rewrite ^/(.*)([^/])$ $scheme://$http_host/$1$2/ permanent;
    }
}

这样排列 root 导致在 php8.locations 中 document_root 实际使用的时 http {} 中的 root

重新调整 dl.tanghui.fun.locations 文件中的 root 命令,如下:

root /srv/nginx/dl.tanghui.fun;

location / {
    index index.html index.php;
    try_files $uri $uri/ /index.php$is_args$args;
    if ( -d $request_filename ) {
        rewrite ^/(.*)([^/])$ $scheme://$http_host/$1$2/ permanent;
    }
}

这样,让 root 命令归属于 server { #dl.tanghui.fun } 这一段中,重启 nginx 测试,显示正常。


内网主机配置 nginx

1、需要将 php.ini 中的 doc_root 设置注释掉

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
                 
;include_path = ".:/php/includes"
;doc_root = "/www"          
user_dir =                  
extension_dir = "/usr/lib/php8"
;sys_temp_dir = "/tmp"   
enable_dl = On         
cgi.force_redirect = 1    
;cgi.nph = 1             
cgi.redirect_status_env = "yes"
cgi.fix_pathinfo = 1 
;cgi.discard_path = 1  
;fastcgi.impersonate = 1        
;fastcgi.logging = 0                    
;cgi.rfc2616_headers = 0
;cgi.check_shebang_line = 1

内网主机配置 frpc


联调 frp 和 nginx


三、应用场景

内网网站发布

网站开发测试


四、参考资料


总结

本文记录在 openwrt-23.05 上配置 frp 和 nginx 实现内网网站在公网发布的调试步骤和解决方法。

  • 84
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值