1.モーションとスタティックを分離する理由
以前のストレステストの結果によると、ホームページで完全なデータを取得する際の主な遅延は、静的リソースのロードです。
その理由は、静的リソースも動的リクエストなどのマイクロサービスに配置され、Tomcatにリクエストを送信して取得する必要があるためです。このように、静的リソースのリクエストはTomcatのスレッドリソースの大部分を占めるため、急激に低下します。スループットで。
次に、静的リソースをすばやく元に戻す必要があり、動的リソースと静的リソースを分離する必要があります
2.コンセプトマップ
以前の動的リクエストと静的リクエストはすべてnginxを介してゲートウェイに渡され、次にマイクロサービスに渡されてtomcatを介してリソースが取得されましたが、現在は次のようになっています。静的リソースをマイクロサービスからnginxに移動すると、静的リソースは次の場合に直接返されます。 nginxにアクセスします。
このように、tomcatは動的リソースを処理するのに十分なスレッドリソースを自由に持つことができ、静的リソースの取得はゲートウェイとマイクロサービスのtomcatを経由して、nginxから直接戻る必要はありません。
3.ハンズオン
(1)将来的にすべての静的リソースをnginxに移動します
nginxフォルダーに静的フォルダーを作成します
[root@10 ~]# cd /
[root@10 /]# ls
bin boot dev -e etc home lib lib64 media mnt mydata opt proc root run sbin srv swapfile sys tmp usr -v vagrant var
[root@10 /]# cd mydata/nginx/
[root@10 nginx]# ls
conf html logs
[root@10 nginx]# cd html/
[root@10 html]# ls
es index.html
[root@10 html]# mkdir static
[root@10 html]# ls
es index.html static
[root@10 html]#
プロジェクト内のインデックスフォルダを静的フォルダにコピーしてから削除します
現時点では、構成がnginxに追加されていないため、アクセスは同じです。
(2)パスマッピングルールを定義します:/ static / **すべてのリクエストはnginxによって直接返されます
conf.dフォルダーの下のgulimall.confを変更して追加します
完全なコマンドは次のとおりです
[root@10 conf.d]# ls
default.conf gulimall.conf
[root@10 conf.d]# vi default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
"default.conf" 45L, 1097C written
[root@10 conf.d]# vi gulimall.conf
root /usr/share/nginx/html;
server {
listen 80;
server_name gulimall.com;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location /static/ {
root /usr/share/nginx/html;
}
location / {
proxy_set_header Host $host;
proxy_pass http://gulimall;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
"gulimall.conf" 49L, 1162C written
[root@10 conf.d]# docker restart nginx
nginx
もう一度ホームページにアクセスして成功を示してください
これまでのところ、nginxの動的および静的分離が実現されています