1. Some time ago, I separated projects before and after learning vue2. After the demo was completed, I wanted to deploy it locally (because there is no Linux machine, I can only simulate deployment on win7), but I encountered a problem when I was learning nginx configuration. , a really incomprehensible problem, the root configuration in nginx's server configuration, the problem is as follows:
According to the official documentation, nginx was started on win7, accessed localhost in the browser, and got a normal page, that is, nginx It started normally, and then I started to modify the configuration.
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index app.html app.htm;
}
location = /img {
root dist;
index app.html app.htm;
}
I saw on some blogs that the path to root is actually the relative path to nginx.exe, so I created a new dist folder:
][1]
It is at the same level as html, and according to the matching priority mentioned on the Internet, the highest equal sign is configured. I think if I visit http://localhost/img at this time, this path should open the app.html in dist. file, but a 404 was reported. I saw this sentence in the log:
D:\nginx\nginx-1.12.0/html/img/index.html" is not found
//D:\nginx\nginx-1.12.0是我的安装目录
nginx goes to the html folder and looks for the index.html file in the img folder;
What I understand is that even if you look for it under html, it should be html/dist/index.html, and it shouldn’t be anything else. img.
So I wondered if it should be an absolute path, so I changed it to the following, killed the process and restarted:
//日志
"D:\nginx\nginx-1.12.0/html/img/index.html" is not found
Still looking for this path, it feels like my second location doesn’t match at all
Then I went to the official website’s guidance document and saw the following paragraph:
server {
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
Then I have an even bigger headache. The path on the official website seems to be an absolute path, but where does this path come from, where is it created, what needs to be configured or what needs to be installed, I don’t understand this root at all;
I can understand other regular matching, priority, port, IP and proxy, etc., but the root can't figure out what's going on.
I hope friends who are familiar with nginx can explain to me in detail what is going on with this root.
1. What happened to the root path?
2. How to change the img configuration so that I can access dist/app.html?
root is the web root directory. It is recommended to use
绝对路径
. The relative path is subject to the working directory of nginx and there is uncertaintyroot is the root directory, use absolute path, so there will be no errors