nginx和apache的安装这么不再赘述,这里直接给出反向代理和负载均衡的配置
nginx动静分离配置如下
server { listen 80; server_name localhost; index index.php index.html; root /data/www/default; location ~ .*\.(jpg|jpeg|png|gif|js|css)$ { expires 1y; } location ~ \.php$ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:88; } }
nginx负载均衡配置如下
http { include mime.types; default_type application/octet-stream; keepalive_timeout 120; tcp_nodelay on; upstream server1 { server 192.168.1.2:80; server 192.168.1.3:80; server 192.168.1.4:80; server 192.168.1.5:80; } upstream server2 { server 192.168.1.7:8080; server 192.168.1.7:8081; server 192.168.1.7:8082; } server { listen 80; server_name 域名1; location / { proxy_pass http://server1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name 域名2; location / { proxy_pass http://server2; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }