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

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

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

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

 

1.获得安装文件

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

 

 2.修改配置文件

2.1 修改conf/nginx.conf

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

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

 

2.2 vhost文件夹

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

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

 

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

 

 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中添加一个图片:

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

 

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

在尾部添加:

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

 

3. 启动nginx

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

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

 

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

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

 

4. 验证成功

4.1 测试文件夹转发

 访问image.imooc.com

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

 

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

 

4.2 测试端口转发

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

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

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