2017.7.1 nginx反向代理服务器域名解析配置(已验证可使用)

下载地址:http://learning.happymmall.com/

 前提:ftpserver已经开启,并且设置为:

 

1.获得安装文件

 

 2.修改配置文件

2.1 修改conf/nginx.conf

引入此文件夹内的配置文件。

 

 

2.2 vhost文件夹

新建文件夹:vhost和相关配置文件。

 

 

 2.3 文件夹转发 vhost/image.imooc.com

注意: root C:\ftpfile\img; 千万不要多加一个\变为root C:\ftpfile\img\;

 1 server { 
 2     listen 80; 
 3     autoindex off; 
 4     server_name image.imooc.com; 
 5     access_log c:/access.log combined; 
 6     index index.html index.htm index.jsp index.php; 
 7     #error_page 404 /404.html; 
 8     if ( $query_string ~* ".*[\;'\<\>].*" ){ 
 9         return 404; 
10     } 
11     location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* { 
12         deny all; 
13     } 
14     location / { 
15         root C:\ftpfile\img; 
16         add_header Access-Control-Allow-Origin *; 
17     } 
18 }

 

并在路径C:\ftpfile\img中添加一个图片:

 

2.4  端口转发 vhost/tomcat.imooc.com
 1 server { 
 2     listen 80; 
 3     autoindex off; 
 4     server_name tomcat.imooc.com; 
 5     access_log c:/access.log combined; 
 6     index index.html index.htm index.jsp index.php; 
 7     #error_page 404 /404.html; 
 8     if ( $query_string ~* ".*[\;'\<\>].*" ){ 
 9         return 404; 
10     } 
11      
12     location / { 
13         proxy_pass http://127.0.0.1:8080; 
14         add_header Access-Control-Allow-Origin *; 
15     } 
16 }

 

2.5 修改本机C:\Windows\System32\drivers\etc\host

在尾部添加:

 

3. 启动nginx

-t的意思是,启动并检查conf是否正确。

 

如果修改了nginx的配置文件,则reload一下即可。

 

4. 验证成功

4.1 测试文件夹转发

 访问image.imooc.com

 

访问image.imooc.com/1.png,出现1.png,则表示文件夹转发成功。

 

4.2 测试端口转发

开启tomcat,访问localhost:8080,出现tomcat首页表示tomcat开启成功。

访问tomcat.imooc.com,出现nginx的首页则表示转发成功。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值