Nginx not redirecting to tomcat

nginxtomcat8

I am using nginx server (nginx version: nginx/1.10.0 (Ubuntu))
created a Tomcat 8 configuration in /etc/nginx/conf.d/tomcat.conf

server {
  listen          80;
  root            /opt/tomcat/webapps/ROOT/;
   server_name mysite.com;
   server_name_in_redirect off;
    access_log /var/log/nginx/site/site_access.log;
    error_log /var/log/nginx/site/site_error.log debug;

  location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cookie_path ~*^/.* /;
        proxy_pass http://localhost:8080;
  }
}

www.site.com is showing Welcome to nginx and my tomcat project is showing on http://ip:8080.

Problem is www.site.com is not redirecting to 8080

Best Answer

You haven't defined a host www.mysite.com, at least not in the config stanza you showed, but there appears to be an additional server {} section in another file that handles www,mysite.com. You need to disable that and add www.mysite.com to the section you showed:

server_name mysite.com www.mysite.com;