一个简单的nginx配置负载均衡的例子
先在hosts文件中添加127.0.0.1 upstream.mynginx.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
server { listen 80; server_name upstream.mynginx.com; access_log /usr/local/var/log/nginx/upstream.mynginx.com.access.log; error_log /usr/local/var/log/nginx/upstream.mynginx.com.error.log; location / { proxy_pass http://my_upstream; } } upstream my_upstream { server 127.0.0.1:8501 weight=100; server 127.0.0.1:8502 weight=100; } server { listen 8501; root /usr/local/var/www/test/nginx_test/upstream/upstream_1; index index.php; location ~ \.php { fastcgi_pass unix:/tmp/php72.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } access_log /usr/local/var/log/nginx/upstream.mynginx.com_8501.access.log; error_log /usr/local/var/log/nginx/upstream.mynginx.com_8501.error.log; } server { listen 8502; root /usr/local/var/www/test/nginx_test/upstream/upstream_2; index index.php; location ~ \.php { fastcgi_pass unix:/tmp/php72.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } access_log /usr/local/var/log/nginx/upstream.mynginx.com_8502.access.log; error_log /usr/local/var/log/nginx/upstream.mynginx.com_8502.access.log; } |