寫了個簡單的nginx負載均衡,發現ie,火狐,edge瀏覽器可以正常,可是谷歌瀏覽器就是不行
程序如下:我是ubuntu系統(虛擬機),ip是192.168.10.100
現在有2個專案,一個是basic2一個是basic3,nginx對應的組態檔如下:
basic2專案組態檔是test2.conf,配置了8078埠
server {
listen 8078;
listen [::]:8078;
root /var/www/html/basic2/web;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
location / {
root /var/www/html/basic2/web;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/basic2/web;
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
basic3專案組態檔是test3.conf,配置了8079埠
server {
listen 8079;
listen [::]:8079;
root /var/www/html/basic3/web;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
location / {
root /var/www/html/basic3/web;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/basic3/web;
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
在瀏覽器分別訪問,結果如下圖:
至此都可以訪問,現在我配置個負載均衡的服務,其組態檔是test.conf,內容如下
server {
listen 80;
listen [::]:80;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name www.yiibasic.cn;
location / {
proxy_pass http://webservers;
}
}
還有nginx的nginx.conf配置如下:
http {
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
upstream webservers {
server 192.168.10.100:8078 weight=1;
server 192.168.10.100:8079 weight=3;
}
include /etc/nginx/conf.d/*.conf;
}
使用權重 1:3 的模式,然后在本機host檔案加入 192.168.10.100 www.yiibasic.cn
當我在火狐,ie下訪問 http://www.yiibasic.cn/ 可以看到 3 次 basic3 出現一次 basic2 出現的周期現象,說明成功了,可是在谷歌上始終是 basic3,偶爾一下 basic3 一下 basic2,快取也清除了,沒有作用,不知道是什么原因??
uj5u.com熱心網友回復:
沒遇到過,坐等其他人uj5u.com熱心網友回復:
用Ctrl+F5重繪試試看uj5u.com熱心網友回復:
自己壓測驗一下,手動瀏覽器刷幾次沒意義uj5u.com熱心網友回復:
如果是快取的話,你在頁面里加上time()時間戳再輸出。或者http的回應內容大小有變化也行。但是,我覺得快取的原因不大。而是好好理解下weight這個配置
它一定會精確地按照你配置的權重去向后段按照比例派發嗎?
uj5u.com熱心網友回復:
坐等結果 坐等結果 坐等結果uj5u.com熱心網友回復:
坐等結果 坐等結果 坐等結果uj5u.com熱心網友回復:
你配的是輪詢嗎?uj5u.com熱心網友回復:
你點url然后再點回車就行了,chrome單純的重繪是不能實作效果的轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/73262.html
標籤:其他技術討論專區
上一篇:簡單下拉框封裝
下一篇:如何實作Qt設計器里面的界面
