nginx 代理服务器 localhost 权限被拒绝 [英] nginx proxy server localhost permission denied

查看:133
本文介绍了nginx 代理服务器 localhost 权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是将 nginx 设置为直接代理到 tomcat 应用服务器的网络服务器.当用户连接到我的网站时,Nginx 应该将请求重定向到运行 Tomcat 应用程序服务器的端口 8080.

I am just setting up nginx as a webserver that proxies directly to a tomcat app server. When the user connects to my website Nginx should redirect the request to port 8080 where the tomcat app server is running.

我正在运行 Redhat 7 的亚马逊 ec2 实例上做所有事情.

I am doing everything on amazon ec2 instance that is running Redhat 7.

到目前为止我所拥有的是:

What I have so far is this:

nginx.conf file

user nginx;
worker_processes  1;

server {
 listen 80;
 server_name mydomainname;
 access_log  /var/log/nginx/example.log;
 error_log /var/log/nginx/example.error.log;

 location / {
  proxy_pass http://localhost:8080/example/;
 }
}

我得到的错误是(13:权限被拒绝)同时连接到上游,客户端

这绝对是用户访问问题,但似乎无法弄清楚.nginx 似乎无权重定向到端口 8080.

This is definitely a user access issue, but cannot seem to figure it out. It seems like nginx does not have access to redirect to port 8080.

另外,nginx是在myuser下运行的

Also, nginx is running under myuser

root     15736   nginx: master process   /usr/sbin/nginx
myuser  15996   nginx: worker process
root     16017   grep --color=auto nginx

我尝试使用 127.0.0.1 而不是 localhost,但没有成功.我也尝试将 nginx.conf 中的用户更改为 myuser,仍然没有运气.当我直接连接到应用程序服务器时,我没有任何问题.

I have tried to put 127.0.0.1 instead of localhost, but no luck. I have also tried to change the user in the nginx.conf to myuser, still no luck. When I connect directly to the application sever I have no issues.

Example URL of my tomcat http://mydomain:8080/example/

先谢谢你.

推荐答案

经过 2 天的搜索,我找到了解决方案.不知何故,SELinux 不允许 Nginx 代理到我的服务器.运行下面的命令修复了问题.

I was able to find a solution after 2 days of searching. Somehow SELinux was not permitting Nginx to proxy to my server. Running the command below fixed the issue.

 /usr/sbin/setsebool -P httpd_can_network_connect true 

感谢@DaveTrux 添加 -P 标志

Adding the -P flag thanks to @DaveTrux

这篇关于nginx 代理服务器 localhost 权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆