1.安装
1、下载nginx源,centos仓库不提供nginx包:
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、安装nginx源:
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
3、安装nginx:
yum install nginx -y
4、启动nginx:
systemctl start nginx
5、打开80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
6、其它命令
nginx -t #检查配置文件语法
systemctl start 服务名
systemctl status 服务名
systemctl restart 服务名
2.常用命令
在nginx.exe目录,打开命令行工具,用命令 启动/关闭/重启nginx
start nginx : 启动nginx
nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx
liunx
systemctl start 服务名
systemctl status 服务名
systemctl restart 服务名
3.常用配置
3.1反向代理监听 192.168.1.207:80 所有请求转到 http://192.168.1.207:8080;
server{
listen 80;
charset utf-8;
server_name 192.168.1.207;
location / {
proxy_pass http://192.168.1.207:8080;
proxy_redirect default;
}
}
3.2负载均衡
#默认轮训
upstream node {
server 192.168.1.207:9999;
server 192.168.1.207:8080;
}
server {
listen 80;
server_name 192.168.1.207;
location / {
proxy_pass http://node;
}
}
#权重weight 1-10 默认1
upstream node {
server 192.168.1.207:9999 weight=2;
server 192.168.1.207:8080 weight=3;
}
server {
listen 80;
server_name 192.168.1.207;
location / {
proxy_pass http://node;
}
}
#最小连接数
upstream node {
least_conn;
server 192.168.0.100:9999;
server 192.168.0.100:8080;
}
server {
listen 80;
server_name 192.168.1.207;
location / {
proxy_pass http://node;
}
}