【商城项目专栏一】Nginx

 

域名解析

    先在本地host解析,解析失败去域名服务器解析,将域名解析成对应的IP,域名备案就是域名绑定IP的过程

Nginx反向代理

    正向代理:配置客户机,将请求代理到一个服务器

    反向代理:客户端请求Nginx,Nginx将请求转发到服务器【客户端不用做任何修改】

    NGINX上配置域名解析,监听80端口【根据域名转发】

本地配置host文件,域名解析

C:\Windows\System32\drivers\etc

添加:

192.168.146.129 manage.leyou.com
192.168.146.129 www.leyou.com
192.168.146.129 api.leyou.com
192.168.146.129 image.leyou.com


虚拟机安装

    1、上传nginx安装包,解压【上传软件:xftp】

上传路径/home/leyou

解压命令:tar xvf nginx   【按table键自动补齐】

删除安装包:rm -rf 。。。

如果XFTP连接不上,换SFTP协议

 

下载地址:http://nginx.org/en/download.html

百度云:https://pan.baidu.com/s/1H_3mR2I7FfDXce-FplghgQ

    2、进入nginx目录执行以下命令   

cd /home/leyou/nginx-1.17.5

指定安装目录在/opt/nginx:./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx

编译安装:make && make install

启动:nginx

停止:nginx -s stop

重新加载:nginx -s reload

查看配置文件地址:nginx -t

报错:

解决办法:https://blog.csdn.net/hybaym/article/details/50929958

yum install -y gcc-c++

yum install -y pcre-devel

yum install -y zlib-devel

然后关闭防火墙,以下是关防火墙碰到的问题

设置防火墙关闭:chkconfig iptables off 然后重启配置【centos7用下面的命令】

临时关闭防火墙:service iptables stop

CentOS之service iptables stop 显示not loaded :https://blog.csdn.net/yelllowcong/article/details/75945339

    3、修改配置文件/opt/nginx/nginx.config

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    client_max_body_size 10m;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    
    server {
        listen       9001;
        server_name  manage.leyou.com;

        location / {
			proxy_pass http://192.168.146.1:9001;

        }
    }

    server {
        listen       80;
        server_name  manage.leyou.com;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
			proxy_pass http://192.168.146.1:9001;
			proxy_connect_timeout 600;
			proxy_read_timeout 600;
        }
    }
    server {
        listen       80;
        server_name  api.leyou.com;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location /api/upload {
		rewrite "^/(.*)$" /zuul/$1;
       }

        location / {
			proxy_pass http://192.168.146.1:10010; # 转发给zuul
			proxy_connect_timeout 600;
			proxy_read_timeout 600;
        }
    }
  
    server {
        listen       80;
        server_name  image.leyou.com;

    	# 监听域名中带有group的,交给FastDFS模块处理
        location ~/group([0-9])/ {
            ngx_fastdfs_module;
        }

        location / {
            root   /leyou/static/;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }

}

   重启nginx:nginx -s reload

    4、访问nginx

 

    5、访问

http://api.leyou.com/api/item/spec/groups2/111?param1=2&param3=3

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值