前期準備是須要安裝apache2和tomcat。apache
Apache的默認端口是80,Tomcat的默認端口是8080。瀏覽器
步驟以下:參考文獻:http://7909846.blog.51cto.com/7899846/1333577/tomcat
(1)cd /etc/apache2/mods-available測試
(2)cp proxy.conf proxy_connect.load proxy.load proxy_http.load /etc/apache2/mods-enabled (須要把這些文件加載到mods-enabled目錄下)ui
(3)找到<IfModule mod_ssl.c>和#</IfModule>,在前面添加#rest
(4)vi /etc/apache2/sites-available/000-default.conf 添加以下代碼: blog
ProxyVia On
ProxyPreserveHost On
ProxyRequests Offssl
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/it
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
Require all granted
</Location>io
RewriteEngine On
RewriteCond %{SERVER_PORT} !^80$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [L,R=301]
(5)保存退出:wq
(6)sudo ln -s /etc/apache2/sites-available/linyupark /etc/apache2/sites-enabled/linyupark (使用ln命令來創建一對關聯文件)
(7)sudo apahe2ctl configtest (測試,顯示OK,表示測試成功)
(8)sudo /etc/init.d/apache2 reload
(9)sudo /etc/init.d/apache2 restart
(10)瀏覽器地址欄輸入 :http://外網IP:80
(9)出現tomcat首頁表示設置成功!