0
点赞
收藏
分享

微信扫一扫

Java8新特性-Stream流

他说Python 2024-06-18 阅读 62

调试笔记-系列文章目录

调试笔记-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 实现内网网站在公网发布的调试步骤和解决方法。

举报

相关推荐

0 条评论