在服务器中,我有一个使用特定URL(http://localhost:8080/bookList)响应的应用程序。我希望此服务器的特定URL由Nginx从外部请求代理。
我通过在外壳中使用以下命令使用maven运行此应用程序(先构建然后运行)
mvn clean install -B
mvn spring-boot:run
当我在服务器上执行此命令时,通过外壳运行的应用程序响应正确;
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
答案 0 :(得分:0)
问题与selinux相关,并通过以下命令解决;
setsebool -P httpd_can_network_connect 1
setenforce 0
这里是说明如何修改selinux以设置nginx反向代理的链接
Using NGINX and NGINX Plus with SELinux
Setting up reverse proxies with NGINX
我想我需要确保使用Nginx适当地安排一些许可,例如使用外部接受请求的