我正在尝试配置NGINX来服务我的Nest应用程序(它运行在Docker上)。
我的应用程序正在侦听端口3000
服务器是amazon linux 2(ec2-用户)
conf文件如下所示:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
#include /etc/nginx/conf.d/nginx.conf;
server {
listen 80;
listen [::]:80;
server_name <ip.adress>;
#web
location / {
add_header X-yahav $uri; # this gets mounted
}
#api
location = /api { # this one is never approached
add_header X-yahav "Api-pass";
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header Host $http_host;
#proxy_pass http://127.0.0.1:3000/;
}
}
}
我想将/api重定向到我的nest应用程序,但它没有它,我得到了一个简单的404,没有我附加的头(正如你可以在conf文件中看到的)
另一件事是,当我转到根目录(location /)时,我确实按预期安装了头文件
有没有觉得哪里不对?
1条答案
按热度按时间kx5bkwkv1#
不要忘记在您的请求中添加“/api”,例如http://your-server:80/api/