【问题标题】:Setting up Spring boot application on Vagrant behind Nginx proxy在 Nginx 代理后面的 Vagrant 上设置 Spring Boot 应用程序
【发布时间】:2017-08-27 05:56:50
【问题描述】:

我有一个在 Vagrant CentOS 机器上运行的嵌入式 Tomcat 上运行的 Spring Boot 应用程序。它在端口 8080 上运行,因此我可以在 Web 浏览器中访问应用程序。 我需要设置 Nginx 代理服务器来监听端口 80 并将其重定向到我的应用程序。

我在 Nginx 日志中收到此错误:

[crit] 2370#0: *14 connect() to 10.0.15.21:8080 failed (13: Permission 拒绝)同时连接到上游,客户端:10.0.15.1,服务器:, 请求:“GET / HTTP/1.1”,上游:“http://10.0.15.21:8080/”,主机: “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: 无法从文件 /run/nginx.pid 读取 PID: 无效 论据

【问题讨论】:

    标签: nginx spring-boot centos vagrant


    【解决方案1】:

    centos 默认启用 SELinux。

    如果关闭则需要通过运行关闭

    setsebool httpd_can_network_connect on
    

    如果您想了解更多信息,请在 Internet 上找到一些关于此的信息。要使其持久化,您可以运行

    setsebool -P httpd_can_network_connect on
    

    【讨论】:

    • 我在 Vagrantfile 中设置了固定 IP。它设置为 10.0.15.21
    • 哦,可能是 SELinux 在你的 centos 机器上阻塞了,你能运行 setsebool httpd_can_network_connect on 并重试吗
    猜你喜欢
    • 1970-01-01
    • 2018-10-01
    • 2017-03-22
    • 2018-09-26
    • 2016-08-10
    • 1970-01-01
    • 2018-12-03
    • 2020-04-04
    • 1970-01-01
    相关资源
    最近更新 更多