nginx做反向 Proxy,實現負載平衡基本配置。無法載入css,js或圖片

來源:互聯網
上載者:User

實現前端一台nginx,後端3台伺服器的負載平衡

我這裡後端的伺服器都是靜態頁面

nginx IP  192.168.1.2

server1:192.168.1.3

server2:192.168.1.4

server3:192.168.1.5

nginx基本配置如下:

worker_processes 4;

worker_cpe_affinity 0001 0010 0100 1000

worker_rlimit_nofile 51200;

events {

use epoll;

worker_connections 51200;

}

http {

include mime.types;

default_type application/octet - stream;  #這個要注意,在解析css js的時候要用到

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

upstream 192.168.1.2 {

server 192.168.1.3:80;

server 192.168.1.4:80;

server 192.168.1.5:80;

}

server {

listen 80;

server_name 192.168.1.2;

charset gbk;

location / {

proxy_pass  http://192.168.1.2;

}

#其他配置略

}

}以上是最簡單基本的配置,本人測試通過。但注意如果你在測試中遇到無法載入後端css或者js或者圖片的問題。先要確定default_type application/octet - stream;然後停止

nginx可以用 pkill -9 nginx 然後 啟動nginx。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.