问题描述
404错误
源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示。
- Nginx服务器配置静态资源映射
在conf目录中找到nginx.conf文件,编辑并增加配置
location /upload { root C:/UPLOAD/; try_files $uri $uri/ /index.html; #解决刷新页面变成404问题的代码 index index.html index.htm; }
增加完成后的配置信息
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;
underscores_in_headers on;
#gzip on;
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /upload {
root C:/UPLOAD/;
try_files $uri $uri/ /index.html; #解决刷新页面变成404问题的代码
index index.html index.htm;
}
#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;
}
}
}
- Tomcat服务器配置静态资源映射
在conf目录中找到server.xml文件,编辑并增加配置
需要增加的配置
<Context debug="0" docBase="C:/UPLOAD" path="/upload" reloadable="true"/>
增加完成后的配置信息
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <Context debug="0" docBase="C:/UPLOAD" path="/upload" reloadable="true"/> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>