商城业务-nginx-搭建域名访问环境一(反向代理配置)

正向代理与反向代理

正向代理:如在进行开发时访问测试环境特定网络,隐藏客户端信息
在这里插入图片描述

反向代理:屏蔽内网服务器信息,负载均衡访问
在这里插入图片描述

Nginx配置文件

在这里插入图片描述
nginx.conf :

# 全局块:
# 配置影响 nginx 全局的指令。如:用户组, nginx进程pid存放路径,日志存放路径,配置文件引,允许生成worker process数等
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

# events块:
# 配置影响 nginx 服务器或与用户的网络连接。如:每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。
events {
    worker_connections  1024;
}

# http块:
# 可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入, mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。
http {
# http全局块
# 如upstream,错误页面,连接超时等
    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;

	# 会包含所有conf.d目录下的conf文件到当前cong文件中,所以我们可以在conf.d目录下新建一个conf文件来进行配置
    include /etc/nginx/conf.d/*.conf;
}

pafcmall.conf :

复制一份 default.conf 为 pafcmall.conf: cp default.conf pafcmall.conf

# server块
# 配置虚拟主机的相关参数,一个http中可以有多个server.
server {
    listen       80;
    #配置pafcmall的域名地址
    server_name  pafcmall.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

	# 配置请求的路由,以及各种页面的处理情况。
    location / {
        # 代理通过,将请求进行转交,要注意末尾要用 分号(;) 来进行结尾
        proxy_pass http://192.168.56.1:10000;
    }

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

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Nginx+Windows搭建域名访问环境

让 nginx 帮我们进行反向代理,所有来自原 pafcmall.com 的请求,都转到商品服务
在这里插入图片描述

先不使用网关,先直接配置 nginx 反向代理到商品服务。

先在docker中设置nginx的开机自启:
在这里插入图片描述

修改nginx的配置文件:

查看nginx.conf文件:
在这里插入图片描述
在这里插入图片描述

配置 pafcmall.conf 文件,先复制一份default.conf文件为pafcmall.conf 文件:

    listen       80;
    #配置pafcmall的域名地址
    server_name  pafcmall.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        #代理通过,将请求进行转交
        proxy_pass http://192.168.56.1:10000;
    }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值