1. 启动和停止Nginx
Nginx目前只支持命令行操作,操作前先进入Dos命令环境,并进入Nginx部署目录。
1) 启动Nginx:start nginx
2) 停止Nginx:nginx -s stop
3) 修改配置后重启:nginx -s reload
2. 负载均衡配置
nginx.conf: worker_processes 1;events { worker_connections 1024;} http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream backend { #ip_hash; server 192.168.1.251; server 192.168.1.252; server 192.168.1.247; } server { listen 80; server_name 2; location / { #设置主机头和客户端真实地址,以便服务器获取客户端真实IP 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_buffering off; #反向代理的地址 proxy_pass http://backend; } } }