我正在尝试添加发送帖子请求的html表单和javascript文件。我把它放在与前端不同的dicrectory中(用角度写)。
这是nginx confg。
server {
listen 80;
real_ip_header X-Forwarded-For;
set_real_ip_from 127.0.0.1;
server_name localhost;
root /var/www/html/psycho-test-rest/psycho_front/dist;
location /download_report/ {
root /var/www/html/psycho-test-rest/psycho_front/user-results;
try_files $uri /resultsdownload.html;
}
location ~ ^/(tests|CRUD)/ {
include uwsgi_params;
uwsgi_pass unix:/var/www/html/psycho-test-rest/socket.sock;
uwsgi_modifier1 30;
}
error_page 404 =200 /index.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我试图在第一个指令中使nginx返回resultsdownload.html
,但总是找不到文件,因为位置块中的根目录总是被全局根替换。这是error.log中的错误。
2018/06/19 05:21:59 [error] 26553#26553: *6 open() "/var/www/html/psycho-test-rest/psycho_front/dist/user-results/resultsdownload.html" failed (2: No such file or directory), client: 212.XXX.XXX.XXX, server: localhost, request: "GET /user-results/resultsdownload.html HTTP/1.1", host: "188.XXX.XXX.XXX"
答案 0 :(得分:1)
/resultsdownload.html
指令的最后一个元素是URI,响应代码或命名位置。有关详细信息,请参阅this document。
location /download_report/
块未处理URI root
,因此不使用该块中定义的location
值。
定义/resultsdownload.html
来处理location = /resultsdownload.html {
root /var/www/html/psycho-test-rest/psycho_front/user-results;
}
URI,例如:
try_files
或者,在try_files $uri /resultsdownload.html =404;
语句中使用 file 参数,例如,通过添加响应代码作为最终参数:
{{1}}