我将nginx用作静态Web服务器和反向代理。
我想获取下一个响应头(连接:keepalive,Content-Leght,ETag):
Server: nginx/1.10.3 (Ubuntu)
Date: Sat, 07 Sep 2019 21:10:35 GMT-2s
Content-Type: text/plain
Content-Length: 210 kilobytes
Last-Modified: Sat, 07 Sep 2019 21:04:01 GMT-6m 36s
Connection: keep-alive
ETag: "5d741b41-3480e"
Accept-Ranges: bytes
我需要在实际配置中添加哪些指令?
它在nginx / 1.10.3 Ubuntu Server 16.04上运行。 通过我的实际配置,我获得了下一个响应头:
Server: nginx/1.10.3 (Ubuntu)
Date: Sat, 07 Sep 2019 21:15:45 GMT-1s
Content-Type: text/plain; charset=utf-8
Connection: close
Expires: Sat, 07 Sep 2019 21:15:44 GMT-2s
Cache-Control: no-cache
upstream app_server {
server 127.0.0.1:5000 fail_timeout=0;
}
server {
listen 80;
server_name _;
# Path for static files WebUI
root /opt/static/www/current;
location = / {
index index.html;
}
location ~* \.html$ {
try_files $uri @proxy_to_app;
expires -1;
}
# First files, then proxy to flask app
# If the original URI can't resolve into a existing file or directory,
# the request is redirected to the named location (proxy_to_app)
location / {
try_files $uri @proxy_to_app;
expires off;
}
# For SSE Server-Sent Events
location /status/events {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Connection '';
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
chunked_transfer_encoding off;
proxy_cache off;
proxy_read_timeout 120s;
expires -1;
proxy_pass http://app_server;
}
location /feeds/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Connection '';
#proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
chunked_transfer_encoding off;
proxy_cache off;
proxy_read_timeout 120s;
proxy_set_header X-NginX-Proxy true;
expires -1;
gzip_static always;
# Forward /feeds/ requests to the application server
proxy_pass http://app_server;
}
# For content that should be handled by mw flask app
# The named location (proxy_to_app) passes the request to a proxied server
(app_server)
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
预先感谢