In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what to do if Nginx FastDFS cannot be accessed". In daily operation, I believe that many people have doubts about what to do when Nginx FastDFS cannot be accessed. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what to do if Nginx FastDFS cannot be accessed". Next, please follow the editor to study!
Problem recurrence
When building a cluster on the server, the unified external access interface is http://192.168.175.110, and the front-end children's shoes are accessed through http://192.168.175.101, and the front-end is accessed with a prefix file, that is, through http://192.168.175.101/file. The first thing I thought of was to forward the front-end request directly to the 192.168.175.110 server via Nginx. The simplified Nginx configuration on the 192.168.175.101 server is shown below.
Upstream file {server 192.168.175.110 max_fails=3;} server {listen 80; server_name 192.168.175.101; location / {root html; index index.html index.htm; # allows cros cross-domain access to add_header 'Access-Control-Allow-Origin'' *'; # proxy_redirect default # for the timeout of connecting to the proxy server, you must note that the time out time cannot exceed 75 seconds. When one server fails, it will be forwarded to another server in 10 seconds. Proxy_connect_timeout 10;} location ~ / file {add_header 'Access-Control-Allow-Origin'' *'; add_header 'Access-Control-Allow-Credentials'' true'; proxy_pass http://file; proxy_set_header Host $host:$server_port;}}
The Ngin I configured on the 192.168.175.110 server is as follows.
Server {listen 80; server_name 192.168.175.110; # charset koi8-r; # access_log logs/host.access.log main; location / {root html; index index.html index.htm; # allow cros cross-domain access to add_header 'Access-Control-Allow-Origin'' *'; # proxy_redirect default # for the timeout of connecting to the proxy server, you must note that the time out time cannot exceed 75 seconds. When one server fails, it will be forwarded to another server in 10 seconds. Proxy_connect_timeout 10;} location ~ / group ([0-9]) {root / data/fastdfs/storage/data; ngx_fastdfs_module;}}
At this point, there is a problem: when the request is forwarded to the 192.168.175.110 server through the file prefix, a 400 status code is returned.
In fact, the location of the problem is relatively simple, that is, the front-end access with an extra file prefix. So, how can we solve this problem?
Problem solving
In general, the reverse proxy of Nginx will only replace the domain name or IP part, and the other parts will be forwarded as is. In other words, when the front end accesses the http://192.168.175.101/file, it is forwarded to the http://192.168.175.110/file, so that the file service interface cannot be accessed properly.
Now that we have located the problem, our next step is to solve the problem. The idea is also relatively simple: remove the file prefix when a request is received on the 192.168.175.101 server. So how to get rid of it?
In fact, it is very simple, only need to add the following configuration to Nginx on the 192.168.175.101 server.
Location ^ ~ / file/ {proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://file/;}
At this point, the Nginx configuration on the 192.168.175.101 server is as follows.
Upstream file {server 192.168.175.110 max_fails=3;} server {listen 80; server_name 192.168.175.101; location / {root html; index index.html index.htm; # allows cros cross-domain access to add_header 'Access-Control-Allow-Origin'' *'; # proxy_redirect default # for the timeout of connecting to the proxy server, you must note that the time out time cannot exceed 75 seconds. When one server fails, it will be forwarded to another server in 10 seconds. Proxy_connect_timeout 10;} location ^ ~ / file/ {proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://file/;}}
At this point, when the http://192.168.175.101/file is accessed again, it is forwarded to the http://192.168.175.110 and the file service interface can be accessed correctly.
Knowledge expansion
How does the nginx reverse proxy configuration remove the prefix?
When using Nginx as a reverse proxy, you can simply forward the request to the next service intact. Setting a proxy_pass request will only replace the domain name. If you want to access different services according to different url suffixes, you need to use the following methods:
Method 1: add "/"
Upstream pay {server localhost:8089 weight=5;} upstream order {server localhost:8090 weight=5;} server {listen 80; server_name binghe.com; location ^ ~ / pay/ {proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for Proxy_set_header X-NginX-Proxy true; proxy_pass http://pay/;} location ^ ~ / order/ {proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true Proxy_pass http://order/;}}
^ ~ / pay/ means to match the request with the prefix pay, and if the proxy_pass ends with /, the path after / pay/* will be directly joined to the end, that is, the pay will be removed.
Method 2: rewrite
Upstream pay {server localhost:8089 weight=5;} upstream order {server localhost:8090 weight=5;} server {listen 80; server_name binghe.com; location ^ ~ / pay/ {proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true Rewrite ^ / user/ (. *) $/ $1 break; proxy_pass http://pay;} location ^ ~ / order/ {proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true Rewrite ^ / order/ (. *) $/ $1 break; proxy_pass http://order;}} at this point, the study on "what to do if Nginx FastDFS cannot be accessed" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.