tomcat启动web程序访问静态资源时404找不到
- UID
- 1066743
|
tomcat启动web程序访问静态资源时404找不到
给web站点配置域名转发后 tomcat启动web程序访问静态资源时404找不到。
经过确认项目资源路径都没问题。
后来经过排查后发现是Nginx的配置问题。
因为做了域名转发 导致 访问路径对应的不是tomcat本身的路径。
主要需要增加配置
server_names_hash_bucket_size 128;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
完整配置
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server_names_hash_bucket_size 128;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server
{
listen 80;
server_name my.525.life;
location / {
#....
proxy_pass http://localhost:8080;
}
##### other directive
location /image/ {
root /usr/local/static/;
autoindex on;
}
}
server
{
listen 80;
server_name yuemei.525.life;
location / {
#....
proxy_pass http://localhost:8000;
}
##### other directive
}
include /etc/nginx/conf.d/*.conf;
} |
|
|
|
|
|