-2

I have installed Nginx server at my cloud space checked by ip it is showing proper page. Now I have also a apache Tomcat8 on port 8080 I want to redirect my port 80 traffic to 8080 for that I am following this tutorial http://www.mkyong.com/nginx/nginx-apache-tomcat-configuration-example/ My problem is I am not getting the path /etc/nginx/sites-enabled/default

I am checing my tomcat application with IP address How to add nxg config detail

3 Answers 3

4

/etc/nginx/sites-enabled/default is the path given to the default website for Debian based systems. They are usually links to files contained /etc/nginx/sites-available.

/etc/nginx/conf.d is a path used in most configurations including Debian derivatives like Ubuntu and other distro's like CentOS etc.

/etc/nginx/nginx.conf is the main configuration file that includes all conf files from one or both of those directories.

You can usually place a configuration file ending in .conf in /etc/nginx/conf.d.

So with that knowledge. Create a conf file with a configuration like the following:

So create a file /etc/nginx/conf.d/tomcat.conf containing a configuration like:

server {
  listen          80;
  server_name     yourdomain.com;

  proxy_cache one;

  location / {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $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;
        proxy_set_header X-Forwarded-Host $host;
  }
}

Note: the proxy_set_headers are useful for logging and apps that need to identify the real client. In theory you can extract the X-Forwarded-For HTTP header to use as the real address for the address of the client in your app or tomcat logs. Otherwise the client will always appear to be the address of the proxy server itself.

4
  • server_name yourdomain.com; should be like server_name abcc.com; or server_name www.abcd.com;
    – xrcwrn
    Aug 29, 2015 at 7:03
  • done this step onening browser is not redirection to tomcat
    – xrcwrn
    Aug 30, 2015 at 11:24
  • @xrcwrn - Is tomcat listening on 127.0.0.1 port 8080 or an macine IP port 8080 ? If it's listening on your local machine IP, then that is why it's not working. Change it to listen on 127.0.0.1
    – hookenz
    Sep 2, 2015 at 0:03
  • Verify tomcat works first. point your browser at 127.0.0.1:8080, If it doesn't come up, don't blame it on nginx.
    – hookenz
    Sep 2, 2015 at 0:04
1

You can use the proxy module in Nginx. Something like this should work:

server {
  listen                *:80;
  server_name           yourserver.com;

  location / {
    proxy_pass http://127.0.0.1:8080;
    include proxy_params
  }
}

https://stackoverflow.com/questions/12847771/configure-nginx-with-proxy-pass

2
  • on which file I will write above content as in mentioned tutorial It is givent to write content in /etc/nginx/sites-enabled/default but I am not getting file I dont have sites-enabled folder. I am only Ip address
    – xrcwrn
    Aug 28, 2015 at 11:42
  • done above but it is not redirecting to tomcat
    – xrcwrn
    Aug 30, 2015 at 11:25
1

You should start with checking compiled-in settings for nginx with nginx -V. It should point you to main configuration file, --conf-path= flag.

All other files should be included with "include" directive in nginx. If you want you can add server {} directive to main configuration file.

Not the answer you're looking for? Browse other questions tagged .