欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

怎么使用Nginx對Laravel進行負載-創(chuàng)新互聯

小編給大家分享一下怎么使用Nginx對Laravel進行負載,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯建站專注為客戶提供全方位的互聯網綜合服務,包含不限于成都做網站、網站建設、疏勒網絡推廣、微信小程序、疏勒網絡營銷、疏勒企業(yè)策劃、疏勒品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們大的嘉獎;創(chuàng)新互聯建站為所有大學生創(chuàng)業(yè)者提供疏勒建站搭建服務,24小時服務熱線:028-86922220,官方網址:chinadenli.net

項目環(huán)境php7.2, nginx , Laravel,開發(fā)的微信公眾號應用 。目前訪問量的上升,單臺服務器不能滿足需求,于是用nginx做了負載。

以下是一種可行性方案,目前正在使用。

session共享的問題參考:Laravel使用Redis共享Session(代碼詳解)

有兩臺web服務器A:10.0.0.2 ,B:10.0.0.3,系統的域名為www.c.com,使用A使用為反向代理服務器

A服務器的nginx配置

server {
listen 81;
server_name _;
index index.html index.htm index.php;
access_log /data/wwwroot/wwwlogs/www_nginx.log combined;
root /data/wwwroot/www/public;
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
location ~ .*\.(php|php5)?$ {
   fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
}

B服務器nginx設置

server {
listen 80;
server_name -;
index index.html index.htm index.php;
access_log /data/wwwlogs/www_nginx.log combined;
root /data/wwwroot/www/public;
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
location ~ .*\.(php|php5)?$ {
 
   fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
}

A 服務器上的反向代理服務器設置

upstream backend{
    ip_hash;
    server 127.0.0.1:81;
    server 10.0.0.3;
}
server {
listen 80;
server_name www.c.com;
index index.html index.htm index.php;
access_log /data/wwwroot/wwwlogs/www_nginx.log combined;
root /data/wwwroot/www/public;
location / {
    proxy_pass http://backend;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(php|php5)?$ {
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
}

如果是做微信公眾號,使用了easywechat,需要把backend 代換為你的www.c.com 這樣才能支持微信授權。

微信的access_token需要使用redis共享,easywechat默認使用laravel 的緩存,所以需要把.env的緩存改成使用redis

CACHE_DRIVER=redis

Laravel 中使用Request::getClientIp()獲取到的IP不是真實的IP,需要修改app/Providers/AppServiceProvider.php,設置信任代理服務器的IP(127.0.0.1,10.0.0.2),就可以使用Request::getClientIp()獲真實IP了。

  public function boot()
    {
        \Request::setTrustedProxies(['127.0.0.1','10.0.0.2']);
    }

以上是“怎么使用Nginx對Laravel進行負載”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯行業(yè)資訊頻道!

新聞名稱:怎么使用Nginx對Laravel進行負載-創(chuàng)新互聯
標題路徑:http://chinadenli.net/article30/deidso.html

成都網站建設公司_創(chuàng)新互聯,為您提供關鍵詞優(yōu)化、營銷型網站建設定制網站、云服務器手機網站建設、商城網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

小程序開發(fā)