18_nginx反向代理配置

1. 一些前置信息

  • nginx已经安装在docker中
  • 项目跑在window系统中

2. 进入nginx配置文件目录

ljs@omnisky:~/mydata/nginx/conf$ ll
total 44
drwxr-xr-x 3 ljs  ljs  4096 9月   2 20:45 ./
drwxrwxr-x 5 ljs  ljs  4096 8月  27 18:13 ../
drwxr-xr-x 2 root root 4096 9月   2 20:57 conf.d/
-rw-r--r-- 1 root root 1007 1月  31  2017 fastcgi_params
-rw-r--r-- 1 root root 2837 1月  31  2017 koi-utf
-rw-r--r-- 1 root root 2223 1月  31  2017 koi-win
-rw-r--r-- 1 root root 3957 1月  31  2017 mime.types
lrwxrwxrwx 1 root root   22 1月  31  2017 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root  701 9月   2 20:45 nginx.conf
-rw-r--r-- 1 root root  636 1月  31  2017 scgi_params
-rw-r--r-- 1 root root  664 1月  31  2017 uwsgi_params
-rw-r--r-- 1 root root 3610 1月  31  2017 win-utf
  • nginx.conf: 是nginx的总配置文件
  • conf.d文件夹下的配置文件是子配置文件

3. 修改总配置文件nginx.conf

sudo vim nginx.conf
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;

    #1. 在http节点下,加入upstream节点,节点名为gulimall
    upstream gulimall{
    # 这个使你想要它代理到哪一个ip地址,可以配置多个实现负载均衡
	server 10.210.30.45:88;
    }
    
    # 引入了哪个包下的配置文件,这个是它默认配好了的
    include /etc/nginx/conf.d/*.conf;
}

4. 进入conf.d包下创建一个新的配置文件,并进行以下配置

cd conf.d
cp default.conf gulimall.conf
vim gulimall.con
server {
    # 如果访问地址是gulimall.com:80
    listen       80;
    server_name  gulimall.com;

    # 则代理到这个地方
    location / {
    # 代理后可能会丢失Host信息,这个使得代理后还有这个host信息
	proxy_set_header Host $host;
	proxy_pass http://gulimall;
    }

    #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;
    }
}

5. 重启nginx即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值