在29安裝nginx,在30和31分別裝上PHP和nginx29伺服器的nginx配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream x.x.x.29 {
server x.x.x.30:8080;
server x.x.x.31:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http:
}
}
}
30和31伺服器的nginx配置
server {
listen 8080;
server_name localhost;
root xx/xxx/public;
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
配置好之後,訪問x.x.x.29,就會把請求分發到30和31伺服器上。
注意
如果有上傳圖片的功能,需要保證靜態資源能共享,解決方案:1.30和31掛載一個共享磁碟儲存檔案,2.使用第三方儲存系統,如oss。