Java – nginx with Tomcat configuration

I'm new to nginx. I need your help,

According to many forums, I learned that all our static pages are stored in nginx When a request arrives, I must pass the request to Tomcat to get the data and generate a Tomcat response after the response

At present, I have just completed my request, passed it directly to Tomcat and responded to the request But I don't think this is a performance solution

So anyone can help me?

Solution

You can use proxy_ Pass is mapped to your Tomcat server port. For example, if your Tomcat port is 8080, your conf / nginx Conf should be configured like this:

...
http {
    ...

    server {
        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

Restart it SBIN / nginx - s reload, and then when you can access http://127.0.0.1 The request is forwarded to Tomcat

Configuration files are usually placed in:

/etc/Nginx/Nginx.conf
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>