【发布时间】:2020-05-12 15:49:24
【问题描述】:
在服务器中,我有一个使用特定 url (http://localhost:8080/bookList) 响应的应用程序。我希望 nginx 从外部请求中代理此服务器的特定 url。
我在 shell 中使用带有以下命令的 maven 运行这个应用程序(首先构建然后运行)
mvn clean install -B
mvn spring-boot:run
当我在服务器中执行此命令时,shell 运行的应用程序响应正确;
curl http://localhost:8080/bookList
这是我的 nginx 配置;
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 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name 10.10.10.10;
location /bookList {
proxy_pass http://localhost:8080/bookList/;
proxy_redirect off;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
}
}
但是当我尝试使用来自外部的 url (http://10.10.10.10/bookList) 浏览器时,我看到下面的错误是 502 Bad Gateway
【问题讨论】:
-
将
proxy_pass http://localhost:8080/bookList/;更改为proxy_pass http://localhost:8080; -
还是不行。
-
任何错误日志条目?
-
我通过禁用 selinux 解决了这个问题。
标签: java nginx reverse-proxy nginx-reverse-proxy nginx-config