1、root賬戶使用命令whereis nginx找打nginx的安裝目錄
2、找到config目錄
3、編輯nginx.conf 如下:
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream xxx-realserver{
server ip1:port1 weight=1; #此處是你被代理的服務的IP和端口,weight代表權重,值越大,流量被分配的越多
server ip2:port2 weight=2; #可配置多個,默認採用輪詢負載策略
}
server{
listen proxy-port; #此處是nginx對外暴露的代理端口
server_name localhost;
location /yourcontext{# yourcontext代表nginx對外代理的上下文
proxy_pass http://xxx-realserver/yourcontext;
}
}
}
4、驗證配置文件的正確性:找到安裝目錄下的sbin目錄,執行./nginx -t命令驗證配置文件的正確性
5、./nginx -s reload重啓nginx即可。