23

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.

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/;
 }
}

The error that I am getting is (13: Permission denied) while connecting to upstream, client

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.

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

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/

Thank you in advance.

user1653068
  • 1,243
  • 1
  • 9
  • 8

2 Answers2

96

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 

Adding the -P flag thanks to @DaveTrux

scrape
  • 43
  • 3
user1653068
  • 1,243
  • 1
  • 9
  • 8
  • 9
    If you add the -P flag to that command it makes the setting persist across reboots. – DaveTrux Jan 12 '16 at 19:11
  • I found this answer googling and can verify that it applies to nginx on CentOS 7.2.1511 as well. Thanks for answering your own question user1653068 and the note about the -P flag from @DaveTrux. – Spanky Quigman Jul 03 '16 at 18:30
  • Hi there, I would like to ask, how do this problem happen? Because when I restart the server, then this happen? I am trying to avoid this happen in next time. Thanks. – Ben Jun 12 '18 at 05:42
  • This same problem occured, and the solution worked on nginx on Fedora. Thank you! – Joon Sep 21 '19 at 13:15
  • So glad I found this solution. Thank you. – SutuwaShell Apr 09 '21 at 20:25
0

you can move to see this issue: stackoverflow questions 23443398

Basically it's the problem of the permission for socket:

Set permissions for unix socket, if one is used. In Linux, read/write permissions must be set in order to allow connections from a web server...

Community
  • 1
  • 1
Fengya Li
  • 4,459
  • 1
  • 14
  • 12
  • 1
    I had already checked that link, but it does not solve my problem.The thing is that my problem is not with PHP. My problem is setting up the reverse proxy server. – user1653068 Aug 13 '14 at 00:36