在laravel5.8中集成swoole组件----用协程实现的服务端和客户端(二)---静态文件如何部署...
目前,較為成熟的技術是采用laravelS組件,注意和laravel 區別laravelS多了一個大寫的S,由于laravelS默認監聽5200端口,所以laravel項目要做一些調整
例如:
- 靜態文件引入的方式-----從靜態資源服務器加載
相關文件的方法。文件laravel5.8官方手冊給出了URL::asset()方法引入,但是例子都過于簡單,如果我們靜態文件的目錄發生改變,則官方文檔中的案例就不再奏效
不過放心,雖然“從靜態資源服務器加載“聽起來要寫一些代碼實現跨域加載似的,但實踐起來并沒那么麻煩
- 項目結構
?
- ngixn 分站點設置
#這段顯得尤為重要---如果沒有,laravel路由方式訪問會提示404 try_files $uri $uri/ /index.php?$query_string;if (!-e $request_filename) {rewrite (.*) /index.php;}}# PHP配置location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}#靜態文件服務器的實現location ~ .*\.(gif|jpg|jpeg|png|js|css)$ {
expires 24h;
root /dingshub2/yinti/public/static;
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /dingshub2/yinti/public/static;#靜態文件訪問路徑,比起域名下的根路徑多了一層/static,沒錯,遇到諸如.css結尾的請求,會到這個路徑下搜尋
proxy_redirect off;
proxy_set_header Host 127.0.0.1;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1;#默認80端口
}
- blade模版文件中的引入
在config文件夾下定義了若干php文件,每個php文件中都返回了一個關聯數組,每個數組的鍵都對應了一個配置方案,例如,我們可以在config下定義一個名為(名稱隨意)
staticfiles.php文件,內容如下: #staticfiles.php
<?php return ['_css_'=>'http://yinti.com:88/mycss','_bstr_'=>'http://yinti.com:88/booststrap4/css','_pic_'=>'http://yinti.com:88/mypic' ];
或者,我們可以在.env文件中定義添加
MYCSS="http://yinti.com:88/mycss" MYPIC="http://yinti.com:88/mypic"blade文件中這樣引入:
母版文件(局部) <!doctype html> <html lang="en"> <head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content=""><meta name="author" content=""><link rel="icon" href="../../../../favicon.ico">@section('title')<title>Sticky Footer Navbar Template for Bootstrap</title>@show<!-- Bootstrap core CSS --> #從config文件夾下的staticfiles.php文件中加載 <link href="{{asset(config('mystatic._bstr_').'/bootstrap.min.css')}}" rel="stylesheet">#從.env文件中加載 <!-- Custom styles for this template -->
<link href="{{asset(env('MYCSS')).'/sticky-footer-navbar.css'}}" rel="stylesheet">
........................剩余部分略去不表
模板繼承文件
@extends('masterpage.login') @section('title')<title>搏擊運動員之家</title> @endsection@section('h1')<h1 class="mt-5">搏擊帥哥魏銳</h1> @endsection @section('plead')<p class="lead">2009年,魏銳考入湖南吉首大學,并因此成為河南周口市鹿邑縣的第一名運動員大學生。 <code>padding-top: 60px;</code> on the <code>body> .container</code>.</p><p>Back to <a href="../sticky-footer">生活中的魏銳,靜若處子,動若脫兔;有如李連杰年輕時的俊郎外表和氣質,表情文靜,態度溫和;賽場上的他,則如猛虎下山,
身形靈動,一次次為夢想而“KO”</a> minus the navbar.</p><p> #從.env文件中加載 <img width="60%" src="{{asset(env('MYPIC').'/9aa88827.jpg')}}"></p> @endsection
- ?路由定義
- 效果
?
轉載于:https://www.cnblogs.com/saintdingspage/p/11267518.html
總結
以上是生活随笔為你收集整理的在laravel5.8中集成swoole组件----用协程实现的服务端和客户端(二)---静态文件如何部署...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新手攻略熔炉_【新手攻略】快速入门
- 下一篇: 如何通过qq发消息获取他人的IP地址。