1、查看主配置类
1.1、主配置类

http {include /etc/nginx/mime.types;default_type application/octet-stream;user nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events {#最大连接数worker_connections 1024;}http {include /etc/nginx/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 /var/log/nginx/access.log main;sendfile on;#tcp_nopush on;keepalive_timeout 65;#gzip on;# 配置的负载均衡,分布式不只一台主机upstream gulimall{server 192.168.144.1:88;}#将server块配置到其他文件并引入include /etc/nginx/conf.d/*.conf;}
1.2、主配置类的结构

2、配置server块
2.1、创建配置文件
cp default.conf gulimall.conf

2.2、配置server块&添加域名
注意点:nginx转发默认会丢掉很多信息,包括域名Host
修改配置
server {#监听的端口listen 80;#监听的域名server_name gulimall.com;#charset koi8-r;#access_log /var/log/nginx/log/host.access.log main;location / {#转发到负载均衡组proxy_pass http://gulimall;#手动设置丢失的host域名proxy_set_header Host $host;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}
3、网关路由
注意点:这个路由规则写在其他规则之后,不然会覆盖其他路由规则
# 通过域名匹配- id: gulimal_host_routeuri: lb://gulimall-productpredicates:- Host=**gulimall.com,gulimall.com
