Home > Article > Backend Development > Nginx location configuration experience
There is a lot of information related to Nginx location configuration. Since 404 Not Found always appears when configuring location, I checked a lot of information and finally found the answer.
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location /hsc { root /home/hsc/nginx; index index.html; } location / { root /home/hsc/nginx/hsc; index index.html index.htm; } }As in the above simple server configuration, enter 127.0.0.1 and 127.0.0.1/hsc in the browser and the result of the request is the same as index.html in the /home/hsc/nginx/hsc directory
Explanation: 127.0.0.1 will match location / and then root (meaning the root directory) is /home/hsc/nginx/hsc. Then nginx will look for the content after / which is empty, so it will look for the content in the root directory.
27.0.0.1/hsc will match llocation /hsc and then root (meaning the root directory) is /home/hsc/nginx and then nginx will find the content behind /. This is the hsc directory, so it will switch to /home/ In the hsc/nginx/hsc directory.
The above introduces the Nginx location configuration experience, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.