遇到问题--Nginx---tomcat启动web程序访问静态资源时404找不到
2018-02-07 11:35
816 查看
http://blog.csdn.net/zzq900503/article/details/76927074
给web站点配置域名转发后 tomcat启动web程序访问静态资源时404找不到。
经过确认项目资源路径都没问题。
后来经过排查后发现是Nginx的配置问题。
因为做了域名转发 导致 访问路径对应的不是tomcat本身的路径。
主要需要增加配置
[java] view
plain copy
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;
完整配置
[plain] view
plain copy
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;
}
给web站点配置域名转发后 tomcat启动web程序访问静态资源时404找不到。
经过确认项目资源路径都没问题。
后来经过排查后发现是Nginx的配置问题。
因为做了域名转发 导致 访问路径对应的不是tomcat本身的路径。
主要需要增加配置
[java] view
plain copy
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;
完整配置
[plain] view
plain copy
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;
}
相关文章推荐
- 遇到问题--Nginx---tomcat启动web程序访问静态资源时404找不到
- 遇到问题--Nginx---tomcat启动web程序访问静态资源时404找不到
- 遇到问题--Nginx---tomcat启动web程序访问静态资源时404找不到
- 遇到问题---web程序访问MongoDB首次超时错误刷新后恢复---Nginx连接时间问题
- 关于nginx+tomcat搭建反向代理时加载静态资源找不到的问题
- ubuntu 部署web应用遇到的问题 tomcat 启动之后 404找不到网页
- nginx作为反向代理访问静态资源出现404问题
- Nginx 访问静态资源报错404 Not Found 的问题解决过程
- web项目中url-pattern改成'/'后,js、css、图片等静态资源(404)无法访问问题解决办法
- 最简单的基于Tomcat的Web应用程序-没有Servlet,只访问静态资源(jsp,html,gif等)
- tomcat配置问题:访问http://localhost:8080/ 遇到 Access Error: 404
- 关于IDEA中无法访问web静态资源的问题
- 在Tomcat上运行Web程序时遇到的一个奇怪问题.
- 【Debug】Web开发中,Tomcat正常启动,访问欢迎页404,怎么办?
- 在tomcat下直接访问Html报错,说找不到资源(404)
- mongodb 遇到的问题记录,开机启动, web 访问
- IIS中遇到无法预览的问题(HTTP 错误 401.3 - Unauthorized 由于 Web 服务器上此资源的访问控制列表(ACL)配置或加密设置,您无权查看此目录或页面。)
- Fedora20 + Nginx + uWSGI + Django环境下访问静态文件可能遇到的问题
- 入职第一天就遇到这样tomcat配置问题,eclipse启动了tomcat正常,可页面还是404。
- WebPack系列:Webpack编译的代码如何在tomcat中使用时静态资源路径不对的问题如何解决