Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The nginx reverse proxy service encountered 404 when accessing resources due to a profile error.

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Recently, when testing the project in hand, there was a 404 error accessing the resources of the server. This is a problem that should not occur, because there is no problem after testing before. Here are the details:

1) all the servers of the company have done nginx reverse proxy.

2) the access path is a virtual path configured in tomcat

3) the server has done disk recovery a few days ago.

Of course, if you have encountered this problem, you can refer to what has not been solved. If you have solved it, please see if there is a problem with my solution. I have just come into contact with Nginx.

When this problem occurs, I first think that there should be a problem with the path, and then modify the virtual path in the configuration file server.xml in tomcat.

Imgss is the virtual path configured by server.xml, and 1444...png is the image to be accessed; there is no problem with the path (but there is a problem when you go to nginx, and the configuration file of nginx will be posted later) this is a 404 page returned by nginx (I didn't notice that it belonged to nginx at that time)

This is strange. Obviously, all the files in the server are there, so how can they not be accessed? then change the previously modified path back (because this path has been tested before, there is no problem with access), and then access other files under this path.

It is found that there is no problem with access, and it can be previewed normally online; then, after many tests, it is found that everything except files in jpg,png format can be accessed normally; and the resources to be accessed by the server are deleted in the server, except for jpg,png files, and then re-initiate access, resulting in a normal 404

Imgss is a virtual path configured by server.xml, and b.PDF does not exist; so it is normal to have 404.

Baidu looked at the information and did not find a solution.

If you look at the local jdk and the jdk on the server again, there is no problem; some people say that it is a packaging problem, but after I repackage, it is still the same problem when I publish it to the server for testing; finally, I wonder if it is the problem with the configuration file of nginx, then check the configuration file localhost; of nginx, which is the path / etc/nginx/sites-available/localhost of the configuration file.

The # comment is added later, but it was not available before. This is the configuration file of the reverse proxy of nginx.

Note this paragraph: location ~. *\. (jpg | js | html | mp3 | gif | jpeg | png | bmp | swf | ico | css) $# set the access static file to be read directly without tomcat

Seeing here, I believe everyone knows what the problem is. When a file is in the format of .jpg / .png, it will map the path to / var/lib/tomcat7/webapps/ROOT; if there is no resource under this path, of course, it will return to nginx's 404 error page; then try to delete the jpg/png, restart the service, and visit again, and it will be normal. This problem should be the reason why the configuration file of nginx was not modified after disk recovery a few days ago.

Of course, the best thing to do is not to delete .jpg / png; and add this code directly to it:

Location ^ ~ / imgss/ {# root / data/customfiles/Files/; # expires 30d; proxy_set_header Host $host; proxy_pass http://127.0.0.1:8080;} location ^ ~ / attachments/ {# root / data/ # expires 30d; proxy_set_header Host $host; proxy_pass http://127.0.0.1:8080}

/ imgss/ and / attachments/ are both virtual paths configured in the tomcat configuration file; nginx will match down layer by layer, and the configured path will be mapped as soon as the match is appropriate

Virtual path of server.xml:

For example, the path we want to access is: https://cache.yisu.com/upload/information/20200622/115/64703.png

Reverse proxy via nginx to: https://cache.yisu.com/upload/information/20200622/115/64735.png, which is the actual location of the resource on the server

After revising it, visit it again and the picture will be loaded successfully. Of course, I have just come into contact with nginx. If there is anything wrong, please give me your advice.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 300

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report