假设有三台服务器 192.168.23.11 192.168.23.12 192.168.23.13
192.168.23.11 作为nginx服务器
192.168.23.12 192.168.23.13作为tomcat服务器
首先安装nginx的环境
配置nginx.conf文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
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;
keepalive_timeout 65;
gzip on;
upstream mywork {
server 192.168.23.12 weight=1;
server 192.168.23.13 weight=1;
}
server {
listen 80;
server_name mywork;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root work;
index index.html;
}
location ~ .*\.(pdf|gif|jpg|jpeg|bmp|png|ico|txt|js|css|ttf|woff)$ {
expires 1d;
root work;
index index.html;
}
location /tata {
proxy_pass http://mywork;
proxy_set_header X-Real-IP $remote_addr;
}
location /nginx_status {
stub_status on;
access_log off;
allow all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
静态的css/js/img等文件存在在nginx服务器
只有需要tomcat的才去请求tomcat服务器
路径要匹配
192.168.23.11/index.html是网站首页
192.168.23.11/tata/是我们tomcat服务器的目录
静态文件的路径需要在work文件中去匹配tata工程的路径