一、该问题的重现步骤是什么?
1. 改gatewey端口为801 直接访问服务器801端口可以正确访问到服务,可是我用nginx代理后,访问80端口提示404
二、你期待的结果是什么?实际看到的又是什么?
期待能跟访问801一样,接口参数可以正常返回。实际访问返回404
直接访问80
直接访问801
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
badex 企业版 nginx/1.18.0 (Ubuntu)
四、请提供详细的错误堆栈信息,这很重要。
nginx日志打印为:
[12/Oct/2024:09:24:01 +0800] "GET /blade-auth/oauth/captcha HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
五、若有更多详细信息,请在下面提供。
nginx的完整配置提供一下
已经提供,见上
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
upstream api_server {
server localhost:801; # API gateway
}
server {
listen 80;
server_name _; # 监听所有域名
# 根路径的配置
location / {
proxy_pass http://api_server; # 反向代理到 API 服务
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 可选:设置超时和缓冲
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
}
# API 路径的配置
location ^~ /api/ {
proxy_pass http://api_server; # 反向代理到 API 服务
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 可选:设置超时和缓冲
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
}
}
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
我们正式线上服务器的配置参考如下,没有问题。
根据你的配置来看,你是把80端口配置到了html页面,不是纯api接口,所以你再写api路径就会404。这种情况你可以另起一个反向代理的前缀比如/api来调用。或者像我们这样单独开一个配置,绑定到域名,然后用80端口。
扫一扫访问 Blade技术社区 移动端