下載地址: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的首頁則表示轉發成功。