安装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的首页则表示转发成功。

 

fighting for this

猜你喜欢

转载自blog.csdn.net/jackcheng1117/article/details/80253954