Nginx 配置访问二级目录
阅读 (3514) 2018-11-22 11:39:45
Nginx 配置访问二级目录
一开始有点被网上教程误导,
错误方法:
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name _;
location / {
root /var/www/html;
try_files $uri $uri/ =404;
}
location /feedback {
root /var/www/html/feedback;
try_files $uri $uri/ =404;
}
实际nginx 在访问feedback之前就已经先到了/根目录中,所以在 / 中写个rewrite即可配置二级目录访问了
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name _;
location / {
root /var/www/html;
rewrite ^~/feedback/.*$ /feedback/ last; #在这里配置二级目录即可
try_files $uri $uri/ =404;
}
更新于:2018-11-22 11:39:45