国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

請(qǐng)教:網(wǎng)站部分靜態(tài)資源的路由配置

lyiply

問題描述

我的項(xiàng)目使用了多應(yīng)用插件,這是我正常的路由【1】
Route::group('/test', function () {
Route::get('/',[app\test\controller\TestController::class, 'index']);
}}
這是我有問題的路由【2】
Route::group('/test', function () {
Route::get('/', function(){ return response('hello webman'); });
}}
我想把首頁改成靜態(tài)文件index.html輸出,但路由【2】只會(huì)返回404,不會(huì)顯示hello webman,
其實(shí)我想要的是路由【3】
Route::group('/test', function () {
Route::get('/', function(){ return response()->file(public_path() . '/test/index.html'); });
}}
我想要把網(wǎng)站部分靜態(tài)化,部分動(dòng)態(tài)化,首頁我靜態(tài)化時(shí)直接訪問域名web.test.com.cn就404,如果域名web.test.com.cn/index.html就正常

為此你搜索到了哪些方案及不適用的原因

1> 多應(yīng)用的關(guān)系nginx那邊不好動(dòng),location不能單獨(dú)對(duì)域名處理,會(huì)影響所有的,如果有方案只影響一個(gè)應(yīng)用也行,我的配置是if ($host = 'web.test.com.cn'){
set $flag "test";
}
rewrite ^/(.*)$ /$flag/$1 last;
2> webman路由【2】不能正常工作,路由【1】是正常的【動(dòng)態(tài)的】,我想要實(shí)現(xiàn)路由【3】的效果沒成功,反復(fù)測(cè)試路由【2】這里就卡死了;路由【2】、路由【3】只會(huì)返回404

我要直接訪問域名web.test.com.cn與就是訪問web.test.com.cn/index.html的效果,麻煩大神指點(diǎn)一下!

504 2 0
2個(gè)回答

muyu

沒明白,如果想首頁是index.html,調(diào)整nginx文件順序不就行了嗎,當(dāng)不是訪問首頁的時(shí)候,走路由

  • lyiply 2025-02-06

    無用,早測(cè)試過了,現(xiàn)在資源訪問都是通過webman框架接管了

  • six 2025-02-06

    截圖
    問AI,加這句就行了

muyu

一下為文心一言生成代碼

server {
    listen 80;
    server_name your_domain.com; # 替換為你的域名或IP地址

    root /path/to/your/webman/public; # Webman的public目錄路徑
    index index.html index.php; # 設(shè)置index.html為首頁,同時(shí)保留index.php以支持Webman的路由

    location / {
        try_files $uri $uri/ /index.html; # 嘗試直接訪問文件或目錄,如果找不到則重定向到index.html

        # 對(duì)于Webman的WebSocket等特定請(qǐng)求,需要轉(zhuǎn)發(fā)到指定的端口(例如9501)
        # 下面的配置假設(shè)你的Webman運(yùn)行在9501端口
        if ($request_method = "POST" ) {
            set $webman_script $uri;
        }

        if ($query_string ~* ".*_route=.*") {
            set $webman_script $uri?$query_string;
        }

        if (-s $document_root$webman_script) {
            rewrite ^(.*)$ $webman_script last;
        }

        # 將所有非靜態(tài)文件請(qǐng)求轉(zhuǎn)發(fā)到Webman的監(jiān)聽端口
        location ~ \.php$ {
            proxy_pass http://127.0.0.1:9501; # Webman運(yùn)行的端口
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_intercept_errors on;
        }

        # 如果不是PHP文件,則嘗試作為靜態(tài)文件服務(wù),如果找不到則回退到index.html
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.html last;
        }
    }

    # 靜態(tài)文件處理,如CSS、JS、圖片等
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 30d;
    }

    # 錯(cuò)誤頁面
    error_page 404 /404.html;
    location = /404.html {
        root /path/to/your/webman/public; # 指定錯(cuò)誤頁面的路徑
        internal;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /path/to/your/webman/public; # 指定錯(cuò)誤頁面的路徑
        internal;
    }
}
  • lyiply 2025-02-06

    DEEPSEEK的回答更準(zhǔn)確一點(diǎn),但執(zhí)行不了,所以來提問

??