在Linux系統(tǒng)中使用nginx來充當(dāng)tomcat的代理服務(wù)器首先我們應(yīng)當(dāng)分別安裝好tomcat和nginx脏里,通常tomcat監(jiān)聽的端口是8080,nginx監(jiān)聽的端口是80枚赡,這些端口都是可以修改的。
為了能夠?qū)崿F(xiàn)nginx代理tomcat我們需要修改nginx的配置谓谦,通常在/etc/nginx/目錄下有一個nginx.conf文件或者在/etc/nginx/conf.d下有個default.conf文件找到
server {
listen? ? ? 80;
server_name? localhost:8080; <-此處原本是server_name? localhost;
#charset koi8-r;
#access_log? /var/log/nginx/log/host.access.log? main;
location / {
# root? /usr/share/nginx/html;<-本行注釋掉
# index? index.html index.htm;<-本行注釋掉
proxy_pass http://localhost:8080;<-添加本行?
}
#error_page? 404? ? ? ? ? ? ? /404.html;
# redirect server error pages to the static page /50x.html
#
error_page? 500 502 503 504? /50x.html;
location = /50x.html {
proxy_pass http://localhost:8080;
# root? /usr/share/nginx/html;
}
保存退出贫橙,然后重啟nginx服務(wù)。
注意7粗唷A匣省!
我在保存退出后重啟了nginx服務(wù)然后去瀏覽器打開http://localhost后發(fā)現(xiàn)顯示的還是原來的nginx的網(wǎng)頁星压,檢測系統(tǒng)進(jìn)程并未發(fā)現(xiàn)nginx的進(jìn)程,然后想到應(yīng)該是瀏覽器緩存的問題鬼譬,所以這時候需要我們強制瀏覽器更新內(nèi)容娜膘,接著就能看到nginx將請求轉(zhuǎn)發(fā)給tomcat了。
附送一個鏈接是在CentOS中安裝nginx的教程优质,非常簡便:
http://my.oschina.net/VincentJiang/blog/224993