1. 程式人生 > >2017.7.1 nginx反向代理伺服器域名解析配置(已驗證可使用)

2017.7.1 nginx反向代理伺服器域名解析配置(已驗證可使用)

 前提: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的首頁則表示轉發成功。