Zero. Preface
The account that has not logged in for a year has finally ushered in an update. After the postgraduate entrance examination, I didn't have fun, and immediately returned to the work of typing code. I haven't been exposed to coding for a year, and the level has decreased. Please forgive me.
1, Problem recurrence
After installing nginx, the project configuration file is introduced into the global configuration file. The test passes and nginx starts running.
However, when the browser accesses the nginx port, the displayed page is only blank. No matter how it is refreshed, it is blank. The symptoms of using different browsers such as Google and Firefox are the same, and the console displays vender JS load failed:
Wrong idea
At first, I didn't pay attention to the vendor's error report. Instead, I checked the network and front-end code:
In fact, the network panel also wrote vendor error, but I didn't take it seriously again,
I ran the front-end code again. It can be displayed normally without nginx forwarding,
Forwarding other items with nginx can also display normally,
Only forwarding this item with nginx will make an error.
2, Problem solving
After reading the online blog, it is the cache directory permission problem. Fix the permission problem.
But there is no point in writing this blog. The more important significance of this article is to find out the problems by yourself.
① Configuration file found
Firstly, due to different systems and installation methods, the nginx configuration files installed by different users are inconsistent. We need to find the configuration files on our computers,
Use nginx -t to find out where the current nginx configuration file is located:
nginx -t //Test the nginx configuration file and return to the file location
The configuration file on my computer is in / opt / homebrew / etc / nginx / nginx conf
(this path is different from most on the Internet, so when we check the data, we should not copy it, but analyze it in combination with the actual situation and specific problems)
② Enable logging
Next, you need to enable the log function to locate the problem. The log function is enabled in the configuration file:
vim /opt/homebrew/etc/nginx/nginx.conf //Enable log file editing
The contents of the document are as follows:
#user nobody; worker_processes 1; #error_log error.log; // The comments here are sample code for the configuration file #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; // (omit other contents here)
Several examples are given in the file. We follow the example of adding a line below to write the path to a path on our computer, such as / var / log / nginx / error Log can also be changed to other:
#user nobody; worker_processes 1; #error_log error.log; #error_log logs/error.log notice; #error_log logs/error.log info; error_log /var/log/nginx/error.log info; //Write the error log to a path #pid logs/nginx.pid;
After saving and exiting, use nginx -s reload to make the changes effective:
We must also ensure that the log write path has permissions. We need to:
// Add read, write and execute permissions to the log folder sudo chmod -R 777 /var/log/nginx/
Next, nginx will automatically go to / var / log / nginx / error Log is written in the file
③ Check logs and troubleshoot problems
We refresh a few times in the browser to let nginx update several logs.
Then view the log:
cat /var/log/nginx/error.log
A lot of information like the following will appear in the log:
2021/12/31 15:33:00 [crit] 92317#0: *9819 open() "/opt/homebrew/var/run/nginx/proxy_temp/2/64/0000000642" failed (13: Permission denied) while reading upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /vendor.js HTTP/1.1", upstream: "http://127.0.0.1:4201/vendor.js", host: "localhost:8015", referrer: "http://localhost:8015/login/login" 2021/12/31 15:33:01 [crit] 92317#0: *9811 open() "/opt/homebrew/var/run/nginx/proxy_temp/3/64/0000000643" failed (13: Permission denied) while reading upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /vendor.js HTTP/1.1", upstream: "http://127.0.0.1:4201/vendor.js", host: "localhost:8015", referrer: "http://localhost:8015/login/login" 2021/12/31 15:33:01 [crit] 92317#0: *9846 open() "/opt/homebrew/var/run/nginx/proxy_temp/4/64/0000000644" failed (13: Permission denied) while reading upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /vendor.js HTTP/1.1", upstream: "http://127.0.0.1:4201/vendor.js", host: "localhost:8015", referrer: "http://localhost:8015/login/login"
In the computer, people can't believe their eyes. They can only believe the real information returned by the computer!
Only after reading the log can we see that the problem of permissions is that the cache directory / opt/homebrew/var/run/nginx / does not have permissions,
So we enter:
sudo chmod -R 777 /opt/homebrew/var/run/nginx/
This solves the permission problem. Refresh again, the page will no longer be blank, and the log will no longer report errors.
This solution is also applicable to other problems.
summary
1, Don't ignore the details. Once you miss the important details, you will take more detours
2, Don't copy the information on the network, but analyze it in combination with the actual situation of your computer
Copyright notice
Author: Mengyunzhi development team of Hebei University of Technology - Liu Yuxuan
Newcomers are inexperienced. If you have any suggestions, you are welcome to communicate. If you have any mistakes, you are welcome to spray lightly