对不同名称的HTML文件使用nginx位置
我希望我的www.example.com/select返回文件/srv/www/example/static/html/select.html 我的example.conf的设置如下所示,但它并没有起到作用对不同名称的HTML文件使用nginx位置,nginx,nginx-location,Nginx,Nginx Location,我希望我的www.example.com/select返回文件/srv/www/example/static/html/select.html 我的example.conf的设置如下所示,但它并没有起到作用 server { server_name mywebsite.com www.mywebsite.com; root /srv/www/mywebsite/static; #charset koi8-r; #access_log /var/log/nginx/host
server {
server_name mywebsite.com www.mywebsite.com;
root /srv/www/mywebsite/static;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location = / {
index html/index.html;
}
location = /select {
index html/select.html;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
尽管返回index.html,但尝试获取/选择将记录此错误
2018/04/28 08:16:59 [error] 17160#17160: *43106 open() "/srv/www/mywebsite/static/select" failed (2: No such file or directory)
如何配置nginx以获得所需的结果?index指令在以
/
结尾的URI上运行,因此在这种情况下不起作用。有关详细信息,请参阅
如果您只有一个URI,则可以使用:
location = /select {
rewrite ^ /html/select.html last;
}
是否有原因将/html/
后缀从根值中去掉?更普遍的解决方案可能是:
root /srv/www/mywebsite/static/html;
location / {
try_files $uri $uri/ $uri.html =404;
}
有关详细信息,请参阅。试用文件解决方案非常完美!非常感谢,祝你今天愉快!