我正在为端口 9001 的所有 HTTP 流量配置代理传递。
Nginx.conf
#user nginx;
worker_processes 1;
#error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
#pid /var/run/nginx.pid;
#include /etc/nginx/modules.conf.d/*.conf;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
include /etc/nginx/sites-enabled/*;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server_tokens off;
#include /etc/nginx/conf.d/*.conf;
}
# override global parameters e.g. worker_rlimit_nofile
include /etc/nginx/*global_params;
可用站点/itdb:
server {
listen 80;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:9001/;
}
}
- 我已验证
sites-available
和sites-enabled
之间的符号链接(symbolic link)完好无损并识别我的配置。 - 我没有收到任何错误,并且所有
nginx-t 测试
都成功成功。 - 我尝试过在代理传递中使用或不使用尾随/。
我有点迷失了还要寻找什么。有什么事情让你印象深刻吗?
最佳答案
您可以验证 nginx 是否正在运行并绑定(bind)到端口 80,如 lsof
和/或fstat
:
这是 OpenBSD 上的 fstat
:
% fstat -u www | fgrep "*:"
www nginx 21404 82* internet stream tcp 0xfffffe833a10d250 *:80
www nginx 21404 83* internet6 stream tcp 0xfffffe833a10d480 *:80
这是 GNU/Linux 上的 lsof
:
% lsof -i -n | fgrep nginx
nginx 24854 root 6u IPv4 61955031 0t0 TCP *:http (LISTEN)
nginx 25047 nobody 6u IPv4 61955031 0t0 TCP *:http (LISTEN)
此外,根据https://serverfault.com/a/870709/110020 ,我建议不要使用 sites-available
/sites-enabled
,因为它也可能会给您带来额外的麻烦。
下一步是运行 curl -v
从运行 nginx 的盒子内,和/或涉及 tcpdump
尝试找出数据包丢失的位置 - 也许您有防火墙?你收到 nginx 的回复了吗?也许是您的后端不可用?
关于http - Nginx 正在运行但未提供服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54701110/