nginx+tomcat動靜態資源分離
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
# 啟用核心複製模式,應該保持開啟達到最快IO效率
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
# HTTP1.1支援持久連線alive
# 降低每個連線的alive時間可在一定程度上提高可響應連線數量,所以一般可適當降低此值
keepalive_timeout 65;
# 啟動內容壓縮,有效降低網路流量
gzip on;
# 過短的內容壓縮效果不佳,壓縮過程還會浪費系統資源
gzip_min_length 1000;
# 可選值1~9,壓縮級別越高壓縮率越高,但對系統效能要求越高
gzip_comp_level 4;
# 壓縮的內容類別
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# 靜態檔案快取
# 最大快取數量,檔案未使用存活期
open_file_cache max=655350 inactive=20s;
# 驗證快取有效期時間間隔
open_file_cache_valid 30s;
# 有效期內檔案最少使用次數
open_file_cache_min_uses 2;
upstream web_app {
server 192.168.0.4:8080 weight=1;
server 192.168.0.4:8081 weight=2;
}
upstream web_test {
server 192.168.0.4:8081 ;
}
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm index.jsp index.do;;
# proxy_pass ;
#}
#配置Nginx動靜分離,定義的靜態頁面直接從Nginx釋出目錄讀取。
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root html;
#expires定義使用者瀏覽器快取的時間為7天,如果靜態頁面不常更新,可以設定更長,這樣可以節省頻寬和緩解伺服器的壓力
expires 7d;
}
location /test {
deny all;
}
location /web {
proxy_pass ;
}
#所有jsp、do的動態請求都交給後面的tomcat處理 location ~ (\.jsp)|(\.do)$
location /
{
#tomcat地址
proxy_pass ;
# 請求頭中Host資訊
proxy_set_header HOST $host;
# 真實的客戶端IP
proxy_set_header X-Real-IP $remote_addr;
# 代理路由資訊,此處取IP有安全隱患
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 真實的使用者訪問協議
proxy_set_header X-Forwarded-Proto $scheme;
# 預設值default,
# 後端response 302時 tomcat header中location的host是http://192.168.1.62:8080
# 因為tomcat收到的請求是nginx發過去的, nginx發起的請求url host是http://192.168.1.62:8080
# 設定為default後,nginx自動把響應頭中location host部分替換成當前使用者請求的host部分
# 網上很多教程將此值設定成 off,禁用了替換,
# 這樣使用者瀏覽器收到302後跳到http://192.168.1.62:8080,直接將後端伺服器暴露給瀏覽器
# 所以除非特殊需要,不要設定這種畫蛇添足的配置
proxy_redirect default;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#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 {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass ;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/196700/viewspace-2103957/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nginx+Tomcat實現動靜分離NginxTomcat
- Nginx+Tomcat負載均衡,動靜分離群集部署解析NginxTomcat負載
- 帶你瞭解Nginx+Tomcat負載均衡,動靜分離群集NginxTomcat負載
- Nginx+Tomcat實現負載均衡、動靜分離叢集部署NginxTomcat負載
- oracle 靜態資料壓縮分離Oracle
- Linux下Nginx+Tomcat負載均衡和動靜分離配置要點LinuxNginxTomcat負載
- 11,nginx動靜分離Nginx
- oracle 靜態歷史資料的壓縮分離Oracle
- xPath 動態分離XML資料XML
- Nginx實現動靜分離Nginx
- Openshift 4.4 靜態 IP 離線安裝系列:準備離線資源
- 013.Nginx動靜分離Nginx
- haproxy + varnish 實現動靜分離
- webpack 靜態資源管理Web
- Web靜態資源加速Web
- Spring Boot MyBatis 動態資料來源切換、多資料來源,讀寫分離Spring BootMyBatis
- 資料庫治理利器:動態讀寫分離資料庫
- 靜態資源伺服器伺服器
- Websphere中靜態資源配置Web
- 網際網路動靜分離架構架構
- 微服務的接入層設計與動靜資源隔離微服務
- 知物由學 | 輿情資料清洗“動”“靜”分離方案
- 008.Nginx靜態資源Nginx
- HAproxy企業應用,TCP/HTTP動靜分離TCPHTTP
- Nginx—tomcat負載均衡動靜分離群集NginxTomcat負載
- Spring動態資料來源+Mybatis攔截器實現資料庫讀寫分離SpringMyBatis資料庫
- 乾貨 | CDN搭配OSS最佳實踐 ——搭建動靜態分離的應用架構應用架構
- Nginx 動靜分離與負載均衡的實現Nginx負載
- nginx反向代理目錄及動靜分離公羊seoNginx
- Nginx + Tomcat 動靜分離實現負載均衡NginxTomcat負載
- ShardingSphere-proxy +PostgreSQL實現讀寫分離(靜態策略)SQL
- Spring Boot 靜態資源配置 A卷Spring Boot
- SpringBoot處理靜態資源Spring Boot
- SpringBoot靜態資源訪問Spring Boot
- asp .net core 靜態檔案資源
- Golang 非主流 打包靜態資源方案Golang
- Nginx靜態資源伺服器配置Nginx伺服器
- wordpress 加速主題的靜態資源