2017-04-02 20 views
1

我有一個運行在Vagrant CentOS上運行的嵌入式Tomcat的Spring引導應用程序。它在8080端口上運行,所以我可以在Web瀏覽器中訪問應用程序。 我需要設置Nginx代理服務器,監聽端口80並將其重定向到我的應用程序。在Nginx代理背後的Vagrant上設置Spring引導應用程序

我得到這個錯誤是Nginx的日誌:

[暴擊] 2370#0:* 14 connect()以10.0.15.21:8080失敗(13:權限 拒絕),同時連接到上游,客戶端: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我可以看到這個日誌。

systemd 1:無法從文件中讀取/run/nginx.pid PID:無效 參數

回答

1

的CentOS已經默認啓用了SELinux。

您需要通過運行

setsebool httpd_can_network_connect on 

,如果你想了解更多有關於這個互聯網上的一些信息,請關閉電源。讓它持久可以運行

setsebool -P httpd_can_network_connect on 
+0

我有一個固定的IP設置在Vagrantfile中。它設置爲10.0.15.21 –

+1

哦,可能是你的Centos盒上的SELinux阻塞,你可以運行setsebool httpd_can_network_connect on並重試 –

+0

看起來就是這個問題。它的工作原理,謝謝! –

相關問題