Nginx+tomcat8 installation manual
1. Version
a) nginx-1.11.8.tar.gz, download address: https://nginx.org/
b) Software environment: centos7, jdk-7u80-linux-x64, apache-tomcat-8.0.38
2. Steps
a) Install the dependencies required to compile Nginx
i. 在linux中执行:yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
ii. Upload Nginx (nginx-1.11.8.tar.gz) to /usr/local/src directory
iii. 编译安装 Nginx
# cd /usr/local/src/
# tar -zxvf nginx-1.11.8.tar.gz
# cd nginx-1.11.8
# ./configure --prefix=/usr/local/nginx
# make && make install
iv. Configure Nginx
# vi /usr/local/nginx/conf/nginx.conf, refer to nginx.conf description
1. user root;#Users and groups used by Nginx
2. worker_processes 2; #Number of subprocesses working (usually equal to the number of CPUs or 2 times the CPU)
3. pid logs/nginx.pid; #Specify pid to store files
4. Add Nginx to achieve load balancing configuration, or use a separate configuration file
upstream 192.168.1.121{
server 192.168.1.121:8080;
server 192.168.1.153:8080;
}
5. proxy_pass http:// 192.168.1.121;
6. Open the corresponding port on the system firewall
vi /etc/sysconfig/iptables
## Nginx
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# service iptables restart
7. Set up Nginx startup
# vi /etc/rc.local
join: /usr/local/nginx/sbin/nginx
8. Test whether Nginx is installed successfully
# /usr/local/nginx/sbin/nginx -t
9. 启动 Nginx
# /usr/local/nginx/sbin/nginx
重启 Nginx
# /usr/local/nginx/sbin/nginx -s reload
停止Nginx
# /usr/local/nginx/sbin/nginx -s stop
******NGINX configure multiple domain names (nginx-1.11.8)
1. Here is an example of configuring 2 sites (2 domain names), n sites can be adjusted accordingly, assuming:
IP address: 192.168.1.100
The domain name 1 ios.1680210.com is placed in /www/ios/site/
The domain name 2 m.1680210.com is placed in /www/webapp/site/
The basic ideas and steps for configuring nginx virtual hosting are as follows:
Put 2 sites in the directory /www/ios/site/ /www/webapp/site/ accessible by nginx
Create an nginx configuration file ios.1680210.com.conf, m.1680210.com.conf for each site, and put the configuration files in /usr/local/nginx/vhosts
Then add an include in /usr/local/nginx/nginx.conf to include all the configuration files created in step 2 (use *)
restart nginx
1. Open the /usr/local/nginx/nginx.conf file and add include in the corresponding location to include the above two files
# Contains all virtual host configuration files
include /usr/local/nginx/vhosts/*;
2. Add m.1680210.com.conf file
server {
listen 80;
#server_name m.1680210.com www.m.1680210.com;
server_name 1680610.com www.1680610.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /www/webapp/site;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root html;
# }
}
3. ios.1680210.com.conf file added
server {
listen 80;
#server_name ios.1680210.com www.ios.1680210.com;
server_name 1680620.com www.1680620.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /www/ios/site;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root html;
# }
}
4. Restart nginx
/usr/local/nginx/sbin/nginx -s reload
5. Load balancing complete configuration example
nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream backend {
#ip_hash;
server 192.168.1.251;
server 192.168.1.252;
server 192.168.1.247;
}
server {
listen 80;
server_name 2;
location / {
#Set the host header and the real address of the client so that the server can get the real IP of the client
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#disable cache
proxy_buffering off;
#address of the reverse proxy
proxy_pass http://backend;
}
}
}
http://www.cnblogs.com/jacktang/p/3669115.html