nginx 代理服务器 localhost 权限被拒绝

编程入门 行业动态 更新时间:2024-10-05 05:18:42
本文介绍了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 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 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 权限被拒绝

本文发布于:2023-11-02 06:48:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551663.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代理服务器   被拒   权限   nginx   localhost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!