在 Nginx 代理后面的 Vagrant 上设置 Spring 引导应用程序
Setting up Spring boot application on Vagrant behind Nginx proxy
我在嵌入式 Tomcat 运行 Vagrant CentOS 机器上有一个 Spring 启动应用程序 运行。它 运行 在端口 8080 上,因此我可以在 Web 浏览器中访问应用程序。
我需要设置 Nginx 代理服务器来侦听端口 80 并将其重定向到我的应用程序。
我在 Nginx 日志中收到此错误:
[crit] 2370#0: *14 connect() to 10.0.15.21:8080 failed (13: Permission
denied) while connecting to upstream, client: 10.0.15.1, server: ,
request: "GET / HTTP/1.1", upstream: "http://10.0.15.21:8080/", host:
"10.0.15.21"
所有设置示例看起来都非常相似,我能找到的唯一可能有帮助的答案是 this one。然而它并没有改变任何东西。
这是我的服务器配置,位于 /etc/nginx/conf.d/reverseproxy.conf
server {
listen 80;
location / {
proxy_pass http://10.0.15.21:8080;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这是我的 nginx.conf 文件'
user root;
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;
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;
}
不知道这个有没有关系,不过在journalctl -u nginx
下可以看到这个日志
systemd1: Failed to read PID from file /run/nginx.pid: Invalid
argument
centos 默认启用 SELinux。
您需要在 运行ning
之前关闭
setsebool httpd_can_network_connect on
如果您想了解更多信息,网上有一些关于此的信息。要使其持久化,您可以 运行
setsebool -P httpd_can_network_connect on
我在嵌入式 Tomcat 运行 Vagrant CentOS 机器上有一个 Spring 启动应用程序 运行。它 运行 在端口 8080 上,因此我可以在 Web 浏览器中访问应用程序。 我需要设置 Nginx 代理服务器来侦听端口 80 并将其重定向到我的应用程序。
我在 Nginx 日志中收到此错误:
[crit] 2370#0: *14 connect() to 10.0.15.21:8080 failed (13: Permission denied) while connecting to upstream, client: 10.0.15.1, server: , request: "GET / HTTP/1.1", upstream: "http://10.0.15.21:8080/", host: "10.0.15.21"
所有设置示例看起来都非常相似,我能找到的唯一可能有帮助的答案是 this one。然而它并没有改变任何东西。
这是我的服务器配置,位于 /etc/nginx/conf.d/reverseproxy.conf
server {
listen 80;
location / {
proxy_pass http://10.0.15.21:8080;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这是我的 nginx.conf 文件'
user root;
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;
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;
}
不知道这个有没有关系,不过在journalctl -u nginx
下可以看到这个日志
systemd1: Failed to read PID from file /run/nginx.pid: Invalid argument
centos 默认启用 SELinux。
您需要在 运行ning
之前关闭setsebool httpd_can_network_connect on
如果您想了解更多信息,网上有一些关于此的信息。要使其持久化,您可以 运行
setsebool -P httpd_can_network_connect on