目标描述
域名mall.test为访问域名,分别复制3个相同的thinkphp做负载均衡。
在nginx配置下定义转发分配规则
nginx.conf
http{
#访问域名
include E:/wnmp/nginx-1.18.0/conf/config/tp6.xy.mall.test.conf;
#引入复制项目1Nginx配置
include E:/wnmp/nginx-1.18.0/conf/config/load/mall7811.test.conf;
#引入复制项目2Nginx配置
include E:/wnmp/nginx-1.18.0/conf/config/load/mall7812.test.conf;
#引入复制项目3Nginx配置
include E:/wnmp/nginx-1.18.0/conf/config/load/mall7813.test.conf;
#定义转发分配规则
upstream mall{
server mall7811.test:7811;
server mall7812.test:7812;
server mall7813.test:7813;
}
}
访问域名tp6.xy.mall.test.conf配置文件
server {
listen 80;
server_name mall.test;
location / {
#解决项目下css,js,图片等静态文件不读取问题
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#设置proxy_pass根据转发规则
proxy_pass http://mall;
}
三个项目文件与正常项目nginx配置文件无差别,只是本地区分的端口
server {
#指定不同的端口
listen 7811;
server_name mall7811.test;
location / {
root E:/wnmp/www/load/mall7811/public;
index index.php index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root E:/wnmp/www/load/mall7811/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#这里$document_root指的是上面定义好的nginx根目录:C:/wnmp/www
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
}
}
1 条评论
1