我试图将我的nginx服务器转发到tomcat(在同一台服务器上)。
我遵循了以下教程:
https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-centos-7 https://www.digitalocean.com/community/tutorials/how-to-encrypt-tomcat-8-connections-with-apache-or-nginx-on-centos-7
但它似乎仍然没有用,虽然它在我以前的服务器上做过。
这是我的nginx配置
....
Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream tomcat {
server 127.0.0.1:8080 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mywebsite.be demo.mywebsite.be;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
#try_files $uri $uri/ =404;
proxy_pass http://tomcat/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
....
当我重新启动nginx并访问我的网站时,我收到以下错误:
“您要查找的页面暂时无法使用。请稍后再试。”
我的tomcat服务器在线并正常工作。
我不知道出了什么问题,我已经重新安装了nginx和tomcat几次。
nginx错误日志会出现以下错误
2017/12/09 13:33:53 [crit] 1288#0: *73 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to
upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET / HTTP/1.1", upstream: "http://127.0.0
.1:8080/", host: "demo.mywebsite.be"
2017/12/09 13:33:53 [crit] 1288#0: *73 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to
upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET /nginx-logo.png HTTP/1.1", upstream: "
http://127.0.0.1:8080/nginx-logo.png", host: "demo.mywebsite.be", referrer: "https://demo.mywebsite.be/"
2017/12/09 13:33:53 [crit] 1288#0: *74 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to
upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET /poweredby.png HTTP/1.1", upstream: "h
ttp://127.0.0.1:8080/poweredby.png", host: "demo.mywebsite.be", referrer: "https://demo.mywebsite.be/"
2017/12/09 13:33:53 [crit] 1288#0: *74 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream, client: 87.**.***.244, server: mywebsite.be, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "demo.mywebsite.be", referrer: "https://demo.mywebsite.be/"
答案 0 :(得分:0)
感谢Richard Smith提出错误日志的想法
我通过运行以下命令解决了这个问题:
/usr/sbin/setsebool httpd_can_network_connect true
如下所述: