Nginx+tomcat8安裝手冊html
1、版本linux
a) nginx-1.11.8.tar.gz,下載地址:https://nginx.org/ios
b) 軟件環境:centos七、jdk-7u80-linux-x6四、apache-tomcat-8.0.38nginx
2、步驟c++
a) 安裝編譯 Nginx 所需的依賴包web
i. 在linux中執行:yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-develapache
ii. 上傳 Nginx(nginx-1.11.8.tar.gz)到 /usr/local/src 目錄centos
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. 配置 Nginx
# vi /usr/local/nginx/conf/nginx.conf,參考nginx.conf說明tomcat
1. user root;#Nginx所用用戶和組
2. worker_processes 2;#工做的子進程數量(一般等於CPU數量或者2倍於CPU)
3. pid logs/nginx.pid;#指定pid存放文件
4. 增長Nginx實現負載均衡配置,也可使用單獨的配置文件
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. 系統防火牆打開對應的端口
vi /etc/sysconfig/iptables
## Nginx
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# service iptables restart
7. 設置 Nginx 開機啓動
# vi /etc/rc.local
加入:/usr/local/nginx/sbin/nginx
8. 測試 Nginx 是否安裝成功
# /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配置多域名(nginx-1.11.8)
1、這裏以配置2個站點(2個域名)爲例,n 個站點能夠相應增長調整,假設:
IP地址: 192.168.1.100
域名1 ios.1680210.com 放在 /www/ios/site/
域名2 m.1680210.com 放在 /www/webapp/site/
配置 nginx virtual hosting 的基本思路和步驟以下:
把2個站點放到 nginx 能夠訪問的目錄 /www/ios/site/ /www/webapp/site/
給每一個站點分別建立一個 nginx 配置文件 ios.1680210.com.conf,m.1680210.com.conf, 並把配置文件放到 /usr/local/nginx/vhosts
而後在 /usr/local/nginx/nginx.conf 裏面加一句 include 把步驟2建立的配置文件所有包含進來(用 * 號)
重啓 nginx
一、打開 /usr/local/nginx/nginix.conf 文件,在相應位置加入 include 把以上2個文件包含進來
# 包含全部的虛擬主機的配置文件
include /usr/local/nginx/vhosts/*;
二、m.1680210.com.conf文件添加
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;
# }
}
三、ios.1680210.com.conf文件添加
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;
# }
}
四、重啓nginx便可
/usr/local/nginx/sbin/nginx -s reload
5. 負載均衡完整配置示例
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 / {
#設置主機頭和客戶端真實地址,以便服務器獲取客戶端真實IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#禁用緩存
proxy_buffering off;
#反向代理的地址
proxy_pass http://backend;
}
}
}
http://www.cnblogs.com/jacktang/p/3669115.html