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.