Nginx configures Java projects to be accessed under Tomcat
- The principle is to use nginx reverse proxy
- The Nginx installation path is /usr/local/nginx
Insert the code piece here > | - client_body_temp | - the conf # this is all Nginx configuration file directory, Extremely important | | - fastcgi. Conf # fastcgi related parameters configuration file | | -- fastcgi. Conf.default# fastcgi. Conf original backup | | - # fastcgi_params fastcgi parameter file | | - fastcgi_params.default| | - koi - utf | | - koi - win | | -- mime. # types media type, | | -- mime. Types.default. | | - nginx conf # this is the main configuration file nginx default | | -- nginx. Conf.default| | - scgi_params # scgi related parameter file, general use less than | | - scgi_params.default| | - uwsgi_params # uwsgi related parameter file, general use less than | | - uwsgi_params.default| ` - win - utf data directory | | - # fastcgi_temp fastcgi temporary, HTML # this is the compilation Nginx default site when installation directory, Similar to the default Apache site htdocs directory | | - 50 x. HTML # error page elegant alternative display files, for example: a502This page # error_page is called when an error occurs500502503504/ 50 x. HTML; | ` -- index. HTML # the default home page file, page file name is in nginx. Defined in advance in the conf. | - logs # this is the default Nginx log path, including the error log and access logs | | - access. Log #, this is the default access Nginx log files using tail -f access. The log, Can watch the site users access to real-time information | | -- error. It is Nginx log # error log files, if Nginx start-up failure and other problems, be sure to look at the error log | ` -- Nginx. Pid # Nginx pid file, Nginx process starts, Will take all the process ID number to the file | - proxy_temp temporary directory | - sbin # # this is Nginx command directory, Such as Nginx start command Nginx | ` - # Nginx Nginx start command Nginx | - scgi_temp # # ` temporary directory -- uwsgi_temp temporary directory9Directories,21 files
Copy the code
- Create a vhost directory in its /usr/local/nginx directory, and then create a tomcats.conf file in the vhosts folder
- The contents of the tomcats.conf file are as follows: For example, two Java projects need to be accessed by Tomcat
server
{
listen 80; server_name ce1.xdr630.top; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http:/ / 127.0.0.1:8081; # Tomcat service address
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server
{
listen 80; server_name ce2.xdr630.top; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http:/ / 127.0.0.1:8082; # Tomcat service address
root html;
index index.html index.htm;
}
error_page 500 502 503 504/50x.html; location = /50x.html { root html; }}Copy the code
- Open the nginx installation directory under the conf nginx. Conf file (my directory is/usr/local/nginx/conf/nginx. Conf.)
- Add at the bottom of the file
include /usr/local/nginx/vhosts/ *; (Including all VM host files)Copy the code
- Then look in the middle of the file
location / {
proxy_pass http:/ / 192.168.0.148:8080; (Add this to specify your own tomcat address)
root html;
index index.html index.htm;
}
Copy the code
Restart Tomcat, nginx. Nginx does not normally need to be restarted. It can be controlled by calling the executable with the -s parameter
- Reloading configuration files:
/usr/local/nginx/sbin/nginx -t // Check the syntax first
/usr/local/nginx/sbin/nginx -s reload // Reload the configuration
Copy the code
Nginx startup status
ps -a | grep nginx
Copy the code
You can also restart the nginx service LNMP restart to access the Tomcat service using the domain name
Supplement:
/ Nginx -h start Nginx: CD sbin; ./nginx