1 .準備三個文件夾,分別存放三個html
文件,文件名和內容以下html
分別在三個文件夾下啓動 http
服務器,http-server
能夠經過 npm install -g http-server
安裝nginx
代理9091端口到9090端口shell
執行sudo vim /etc/nginx/sites-enabled/test
,並添加如下內容npm
server { listen 9090; server_name test_nginx; location / { proxy_pass http://localhost:9091; } }
測試ngxin
配置文件vim
sudo nginx -t
應用nginx
配置瀏覽器
sudo nginx -s reload
打開瀏覽器測試服務器
執行sudo vim /etc/nginx/sites-enabled/test
,修改文件爲負載均衡
upstream test_upstream { server localhost:9091; server localhost:9092; server localhost:9093; } server { listen 9090; server_name test_nginx; location / { proxy_pass http://test_upstream; } }
測試ngxin
配置文件測試
sudo nginx -t
應用nginx
配置spa
sudo nginx -s reload
打開瀏覽器測試,多刷新幾回