nginx+多個tomcat配置

1、nginx核心配置:

nginx.conf文件配置以下:

  #這裏的 upstream和下邊server_name要一致  都是"localhost"表示本地,也能夠是網站域名(注意不包括http://)
	upstream localhost_tomcat {
	server 172.16.4.79:8888;
	server 172.16.4.79:8889;
	}

    server {
        listen       80;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
		#本身指定要跳轉的域名
		server_name localhost;
	   #下邊是靜態資源配置,放在nginx服務器下,在目錄resources/ROOT底下。
 	   location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
 			  root  resources/ROOT;
 			  #expires定義用戶瀏覽器緩存的時間爲7天,若是靜態頁面不常更新,能夠設置更長,這樣能夠節省帶寬和緩解服務器的壓力
 			  expires	7d; 

        location / {
		#此處配置的域名必須與upstream的域名一致,才能轉發。
		proxy_pass http://localhost_tomcat;
            #root   html;
            #index  index.html index.htm;
        }
 	}
相關文章
相關標籤/搜索