遇到问题--Nginx---tomcat启动web程序访问静态资源时404找不到

http://blog.csdn.net/zzq900503/article/details/76927074



给web站点配置域名转发后 tomcat启动web程序访问静态资源时404找不到。


经过确认项目资源路径都没问题。


后来经过排查后发现是Nginx的配置问题。


因为做了域名转发 导致 访问路径对应的不是tomcat本身的路径。



主要需要增加配置

[java]  view plain  copy
  1. server_names_hash_bucket_size  128;  
  2. proxy_redirect off;  
  3. proxy_set_header Host $host;  
  4. proxy_set_header X-Real-IP $remote_addr;  
  5. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  





完整配置

[plain]  view plain  copy
  1. user  nginx;  
  2. worker_processes  1;  
  3.   
  4. error_log  /var/log/nginx/error.log warn;  
  5. pid        /var/run/nginx.pid;  
  6.   
  7.   
  8. events {  
  9.     worker_connections  1024;  
  10. }  
  11.   
  12.   
  13. http {  
  14.     include       /etc/nginx/mime.types;  
  15.     default_type  application/octet-stream;  
  16.   
  17.     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  18.                       '$status $body_bytes_sent "$http_referer" '  
  19.                       '"$http_user_agent" "$http_x_forwarded_for"';  
  20.   
  21.     access_log  /var/log/nginx/access.log  main;  
  22.   
  23.     sendfile        on;  
  24.     #tcp_nopush     on;  
  25.   
  26.     keepalive_timeout  65;  
  27.   
  28.     #gzip  on;  
  29.   
  30.   server_names_hash_bucket_size  128;  
  31.     proxy_redirect off;  
  32.     proxy_set_header Host $host;  
  33.     proxy_set_header X-Real-IP $remote_addr;  
  34.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  35.   
  36.   
  37.   
  38.   
  39. server  
  40. {  
  41.     listen 80;  
  42.     server_name my.525.life;  
  43.     location / {  
  44.         #....  
  45.         proxy_pass http://localhost:8080;  
  46.     }  
  47.     ##### other directive  
  48.   
  49. location /image/ {    
  50.             root   /usr/local/static/;    
  51.             autoindex on;    
  52.         }  
  53.   
  54.   
  55.   
  56. }  
  57.   
  58.   
  59. server  
  60. {  
  61.     listen 80;  
  62.     server_name yuemei.525.life;  
  63.     location / {  
  64.         #....  
  65.         proxy_pass http://localhost:8000;  
  66.     }  
  67.     ##### other directive  
  68. }  
  69.    
  70.   
  71.   
  72.     include /etc/nginx/conf.d/*.conf;  
  73.   
  74.   
  75. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值