Install and configure Nginx in Linux (Ubuntu) and integrate it with Tomcat

Source: Internet
Author: User
Tags gz file
Use Nginx in UbuntuLinux for the first time and keep a record. I have been installed through sudoapt-getinstallnginx. if the tar.gz file is downloaded from the local directory, the package dependency needs to be resolved. After the installation, the following are common commands: sudonginx # Start sudong‑sstop # Stop sudong‑t # test whether the configuration file is correct. This command is useful. In addition, you can find

Use Nginx in Ubuntu Linux for the first time and keep a record.

I installed nginx through sudo apt-get install nginx. if the tar.gz file is downloaded from the local directory, the package dependency needs to be resolved.

After installation, the following are common commands:

Sudo nginx # Start

Sudo nginx-s stop # stop

Sudo nginx-t # test whether the configuration file is correct. This command is useful.

In addition, you can find on the Internet to make the changed configuration take effect without stopping the nginx service:

Kill-HUP 'cat/usr/local/nginx. Pi' # not tested. I wonder if it is possible


In addition, it is best to delete/doc and/images after nginx is installed,

Sudo vi/etc/nginx/sites-available/default

Delete location/doc {} and location/images.


Integrate tomcat.

Sudo vi/Etc/nginx/conf. d/proxy. conf

Enter the following content:

#! Nginx (-)
# Proxy. conf
Proxy_redirect off;
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr; # obtain the Real ip Address
# Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; # obtain the real ip address of the proxy
Client_max_body_size 10 m;
Client_body_buffer_size 128 k;
Proxy_connect_timeout 90;
Proxy_send_timeout 90;
Proxy_read_timeout 90;
Proxy_buffer_size 4 k;
Proxy_buffers 4 32 k;
Proxy_busy_buffers_size 64 k;
Proxy_temp_file_write_size 64 k;


Assume that http: // localhost: 8080/temp/index. jsp is running on tomcat.

Then: sudo vi/etc/nginx/sites-avalable/defalut

Add the following to server:

Location ~ . *. [Jsp | do | action] $ {# All jsp pages and do/action requests are handled by tomcat.
Index. jsp;
Proxy_pass http: // localhost: 8080; # Switch to tomcat
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ {# Set to directly read static files without passing through tomcat
Expires 30d;
}
Location ~ . * \. (Js | css )? $ {
Expires 1 h;
}

Open http: // localhost/temp/index. jsp, which is consistent with http: // localhost: 8080/temp/index. jsp.

Note: This article is written in reference to the above documents.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.