![curl nginx 作为代理服务器使用“-i”可以工作,但使用“-I”时会出现 404](https://linux22.com/image/760844/curl%20nginx%20%E4%BD%9C%E4%B8%BA%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%BF%E7%94%A8%E2%80%9C-i%E2%80%9D%E5%8F%AF%E4%BB%A5%E5%B7%A5%E4%BD%9C%EF%BC%8C%E4%BD%86%E4%BD%BF%E7%94%A8%E2%80%9C-I%E2%80%9D%E6%97%B6%E4%BC%9A%E5%87%BA%E7%8E%B0%20404.png)
为了进行压缩测试,我尝试将 nginx 作为代理服务器连接到端口 3000 上的 nodejs 应用程序,如下所示:
curl -I -H 'Accept-Encoding: gzip, deflate' http://localhost/json
我去这个:
当使用 -i 卷曲它时,显示主体
curl -i -H 'Accept-Encoding: gzip, deflate' http://localhost/json
我懂了:
在 nginx.conf 文件中:
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:3000;
}
在节点 app.js 中
//..
app.get('/json',(req,res)=>{
res.json({Hello:'JSON'})
});
当发送一些文本来测试 gzip 时这似乎又很奇怪
app.get('/', (req,res)=>{
res.end('lorem ipsum ........ 100(lorem ipsum long text) ');
});
内容没有减少,但是当我明确添加内容类型时,内容大小被压缩了。
app.get('/', (req,res)=>{
res.setHeader('Content-type','text/html');
res.end('lorem ipsum ........ 100(lorem ipsum long text) ');
});
答案1
-I
发出 HEAD 请求,同时-i
发出 GET 请求。
您的应用很可能仅回答 GET 请求。