国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

云服務器|WEB服務器|FTP服務器|郵件服務器|虛擬主機|服務器安全|DNS服務器|服務器知識|Nginx|IIS|Tomcat|

服務器之家 - 服務器技術 - Nginx - 使用nginx+tomcat實現靜態和動態頁面的分離

使用nginx+tomcat實現靜態和動態頁面的分離

2019-11-19 17:42菜鳥_lch Nginx

這篇文章主要介紹了使用nginx+tomcat實現靜態和動態頁面的分離,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧。

博主最近在優化一個javaweb項目,該項目之前一直都是使用tomcat處理用戶請求的,無論靜態還是動態的東西,一律交給tomcat處理。tomcat主要是負責處理servlet的,靜態的文件還是交給nginx處理,nginx對靜態文件的處理比tomcat不是只快了一點,并且Nginx的使用對項目并發能力有很大的提升。下面主要記錄下主要的配置過程:

實驗環境:windows

實驗工具:Nginx、tomcat

windows下安裝Nginx非常簡單,去官網下載壓縮包解壓后并且雙擊解壓目錄下的nginx.exe程序即可。然后在瀏覽器輸入localhost可出現下圖,即表示nginx已經在工作。

使用nginx+tomcat實現靜態和動態頁面的分離 

nginx的工作流程是:對外,nginx是一個服務器,所有的請求都先請求到nginx,然后再由nginx對內網進行請求的分發到tomcat,然后tomcat處理完請求后將數據發送給nginx,然后由nginx發送給用戶,整個過程對用戶的感覺就是nginx在處理用戶請求。既然這樣子,nginx肯定需要進行配置,主要的配置文件是conf文件夾下的nginx.conf,因為我主要是進行了靜態與動態分離,所以沒有進行靜態文件緩存,也沒有進行負載均衡的配置。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#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 {
  #nginx默認最大并發數是1024個用戶線程
  worker_connections 1024;
}
 
 
http {
  include    mime.types;
  default_type application/octet-stream;
 
  #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;
 
  sendfile    on;
  #tcp_nopush   on;
 
  #keepalive_timeout 0;
  #http1.1在請求完之后還會保留一段時間的連接,所以這里的timeout時長不能太大,也不能太小,
  #太小每次都要建立連接,太大會浪費系統資源(用戶不再請求服務器)
  keepalive_timeout 65;
 
  #gzip on;
 
  server {
  #nginx監聽80端口
    listen    80;
    server_name localhost;
 
    #charset koi8-r;
 
    #access_log logs/host.access.log main;
  #這里的/表示所有的請求
    #location / {
    #將80端口的所有請求都轉發到8080端口去處理,proxy_pass代表的是代理路徑
   #  proxy_pass http://localhost:8080;
     # root  html;
      # index index.html index.htm;
    #}
 
  #對項目名進行訪問就去訪問tomcat服務
  location /Student_Vote {
      proxy_pass http://localhost:8080;
  }
 
  #對jsp和do結尾的url也去訪問tomcat服務
  location ~ \.(jsp|do)$ {
      proxy_pass http://localhost:8080;
  }
  
  #對js、css、png、gif結尾的都去訪問根目錄下查找
  location ~ \.(js|css|png|gif)$ {
      root F:/javaweb;
  }
 
 
    #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  http://127.0.0.1;
    #}
 
    # 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;
  #  }
  #}
 
}

上面的配置中我把默認的location /給注釋掉了,因為它會攔截所有的請求,無論是動態還是靜態,還有一個就是對靜態文件的配置我配置成了javaweb的工作區間,接下來會說明為什么。

因為之前寫的項目一直以來都是使用jsp內置對象來進行目錄的文件訪問,但是使用了nginx一切都需要改變,當我使用了nginx,并且項目沒有進行路徑的修改的時候,總是無法加載靜態文件,查看日志發現這樣的錯誤:2016/05/20 18:27:30 [error] 6748#6936: *225 CreateFile() "F:/javaweb/Student_Vote/lib/images/username.png" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /Student_Vote/lib/images/username.png HTTP/1.1", host: "localhost", referrer: "http://localhost/Student_Vote/index.jsp",大致信息是根據jsp中文件的配置,nginx將會從/Stdent_Vote(這是我的項目名)/lib/images包中查找靜態文件,而我又不想對項目文件做太大變化,其實還有一種方法是不使用jsp的內置對象,直接使用http://localhost/username.png來代替內置對象訪問靜態文件,但是這樣改要改很多的地方,所以我就直接將web-inf文件夾下的lib文件夾拷到上一個文件夾,也就是該文件夾和web-inf文件夾是兄弟文件夾的關系。

通過上述操作,就實現了動態與靜態的分離了,無圖無真相,下面展示效果圖。

使用nginx+tomcat實現靜態和動態頁面的分離

上圖可以看到server是“Apache-Coyote/1.1”。tomcat的連接器就是這個。

使用nginx+tomcat實現靜態和動態頁面的分離

而上面的server可以看到是nginx,說明對外而言接收請求的服務器是nginx。

 以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.cnblogs.com/liucaihao/p/5513709.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 亚洲免费视频观看 | 日韩不卡一区二区三区 | 久久e久久 | 在线视频一区二区 | 天堂资源在线 | 日韩中文视频 | 一区二区免费视频 | 91在线麻豆| 91在线影院 | 日日夜夜精品 | 成人福利在线 | 国产成人av在线播放 | 婷婷久久五月天 | 久久久91精品国产一区二区三区 | 免费一级网站 | 国产精品久久久久国产a级 九九在线精品视频 | 中文av电影| 日韩成人高清视频 | 亚洲欧美另类久久久精品2019 | 国产精品久久久久久久一区探花 | 亚洲视频在线观看 | 免费人成黄页网站在线一区二区 | 国产成人精品一区二区三区四区 | 大桥未久亚洲精品久久久强制中出 | 日韩欧美三区 | 国产精品亚洲视频 | 亚洲综合色网 | heyzo 在线| 一区二区视频 | 中文字幕亚洲专区 | 日本美女一区二区三区 | 亚洲免费影院 | 日韩中文字幕在线免费观看 | 97超碰免费 | 亚洲最新无码中文字幕久久 | 国产高清视频一区二区 | 国产精品美女久久久久久久网站 | 天堂va在线高清一区 | 亚洲精品久久久久久国产精华液 | 午夜精品在线观看 | 国产视频色|