1

I am first time working with Nginx.

  • I have two servers. SERVER ONE (ip : 1.2.3.4) SERVER TWO (ip : 5.6.7.8)
  • I have Installed nginx on SERVER ONE and Tomcat on SERVER TWO.
  • I have successfully configured tomcat to run on different port. My tomcat is running on following ports.

    5.6.7.8:8080
    5.6.7.8:8081
    5.6.7.8:8082

  • I have also deployed my war file on tomcat(each of the instance).

  • I have configured my nginx as follows

  • created a default.conf in /etc/nginx/conf.d

  • Made changes to the file according the following link Nginx Configuration

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
        # Make site accessible from http://localhost/
        server_name 1.2.3.4;
    
        location / {
                proxy_pass http://www.example.com;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rule
        }
    
        location /user/{
                proxy_pass http://5.6.7.8:8080$uri;
    
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rule
        }
    

    }

  • The name of War file which I deployed on SERVER TWO is Example.
    which contains a api /user/login?param1=xyz&param2=abc&param3=mno

  • When I hit the ip 1.2.3.4, it goes to root(/). I am getting the expected result.I am getting the example.com page.
  • But when I hit 1.2.3.4/user, I am getting 404 not found. I was expecting that my api will be called and I will get the result.
  • To check whether my api is working or not if I hit
    5.6.7.8:8080/Example//user/login?param1=xyz&param2=abc&param3=mno. I am getting the correct json result which I was expecting.
  • And this same result I am expecting when I hit 1.2.3.4/user.But I am getting 404.

What all things I have to change in order to get the result when I hit 1.2.3.4/user

Thank you

1 Answer 1

1

The only problem was the try_files I commented the try files and every thing is working correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.