应用场景
原本是通过网关(10.22.5.58)调用demo(10.22.5.44),现在使用nginx替代网关,配置nginx做反向代理
demo调用方式:
(1)http://10.22.5.44:8081
(2)/provider
(3)请求头:Content-Type:application/x-www-form-urlencoded
(4)请求方式post
(5)请求参数a
安装nginx
官网地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS
针对CentOS安装如下:
1、输入命令sudo yum install yum-utils
2、新增文件/etc/yum.repos.d/nginx.repo内容如下:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3、输入命令sudo yum install nginx进行安装
启动nginx
systemctl start nginx
systemctl stop nginx
systemctl status nginx
配置文件
/etc/nginx/nginx.conf,启动nginx时默认启动该文件
http节点下增加配置如下:
访问nginx的10.22.5.58:8020/my时转发到10.22.5.44:8081
upstream demo_server {
server 10.22.5.44:8081;
keepalive 2000;
}
server {
listen 8020;
server_name 10.22.5.58;
client_max_body_size 1024M;
location /my/ {
proxy_pass http://demo_server/;
proxy_set_header Host $host:$server_port;
}
}
配置项
1、user nginx
启动用户,安装时会自动去创建这个用户
2、worker_processes
配置与CPU核数一致
3、worker_connections
4、worker_cpu_affinity
列出具体的CPU,例如0001代表第一个,0010代表第二个,0100代表第三个,1000代表第四个
访问方式