Nginx+Tomcat+Https 服務(wù)器負(fù)載均衡配置實(shí)踐方案詳解
由于需要,得搭建個(gè)nginx+tomcat+https的服務(wù)器,搜了搜網(wǎng)上的發(fā)現(xiàn)總是有錯(cuò),現(xiàn)在整理了些有用的,備忘。
環(huán)境:Centos6.5、JDK1.8、Tomcat8、Nginx1.10.1
準(zhǔn)備材料:
1.JDK1.8安裝包jdk-8u102-linux-x64.tar.gz
2.Tomcat8安裝包apache-tomcat-8.0.37.tar.gz
3.Nginx1.10安裝包nginx-1.10.1.tar.gz
1、JDK安裝配置
解壓并安裝到/usr/local/jdk
[root@localhost ~]# tar zxvf jdk-8u102-linux-x64.tar.gz [root@localhost ~]# mv jdk1.8.0_102 /usr/local/jdk
配置JDK環(huán)境變量
[root@localhost ~]# vi /etc/profile
在底部加入以下內(nèi)容
JAVA_HOME=/usr/local/jdk JRE_HOME=$JAVA_HOME/jre CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH export JAVA_HOME JRE_HOME PATH CLASSPATH
應(yīng)用環(huán)境變量
[root@localhost ~]# source /etc/profile
檢測(cè)是否成功,顯示版本說(shuō)明成功
[root@localhost ~]# java -version
2、Tomcat安裝配置
解壓并安裝到/usr/local/tomcat
[root@localhost ~]# tar zxvf apache-tomcat-8.0.37.tar.gz [root@localhost ~]# mv apache-tomcat-8.0.37 /usr/local/tomcat
默認(rèn)tomcat是root身份運(yùn)行的,這樣不安全,這里設(shè)置普通用戶運(yùn)行
[root@localhost ~]# groupadd tomcat [root@localhost ~]# useradd -g tomcat tomcat [root@localhost ~]# passwd tomcat [root@localhost ~]# chown tomcat.tomcat -R /usr/local/tomcat
運(yùn)行tomcat
[root@localhost ~]# su - tomcat /usr/local/tomcat/bin/startup.sh
設(shè)置開(kāi)機(jī)啟動(dòng)
[root@localhost ~]# echo "su - tomcat /usr/local/tomcat/bin/startup.sh" >> /etc/rc.local
3、Nginx安裝配置
配置Nginx用戶
[root@localhost ~]# groupadd nginx [root@localhost ~]# useradd -g nginx -s /sbin/nologin nginx
安裝依賴包
[root@localhost ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++
解壓并進(jìn)入文件夾內(nèi)
[root@localhost ~]# tar zxvf nginx-1.10.1.tar.gz [root@localhost ~]# cd nginx-1.10.1
配置安裝
[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module [root@localhost nginx-1.10.1]# make && make install
配置Nginx
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
這一步需要手動(dòng)將ssl證書(shū)放入/usr/local/nginx/conf/目錄下,分別為cert.crt和cert.key文件
如果證書(shū)文件是其他格式,可以自行搜索轉(zhuǎn)換方法
如果無(wú)須配置https,更改443端口即可
nginx主配置文件
user nginx;
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 6 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascripttext/css application/xml;
gzip_vary on;
server {
listen 80;
server_name www.domain.com; #修改域名
return 301 https://$server_name$request_uri; #強(qiáng)制跳轉(zhuǎn)443端口
}
server {
listen 443 ssl;
server_name www.domain.com; #修改域名
ssl_certificate cert.crt; #導(dǎo)入證書(shū)
ssl_certificate_key cert.key; #導(dǎo)入證書(shū)
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/local/tomcat/webapps/ROOT;
index index.html index.jsp index.htm;
}
location ~ .*.jsp$ {
index index.jsp;
proxy_pass http://127.0.0.1:8080;
}
location /nginxstatus {
stub_status on;
access_log on;
auth_basic "nginxstatus";
auth_basic_user_file /usr/local/nagois/etc/htpasswd.users;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
啟動(dòng)服務(wù)器
/usr/local/nginx/sbin/nginx
瀏覽器訪問(wèn)出現(xiàn)小貓即成功。
以上所述是小編給大家介紹的Nginx+Tomcat+Https 服務(wù)器負(fù)載均衡配置實(shí)踐方案詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
nginx+apache+mysql+php+memcached+squid搭建集群web環(huán)境
當(dāng)前,LAMP開(kāi)發(fā)模式是WEB開(kāi)發(fā)的首選,如何搭建一個(gè)高效、可靠、穩(wěn)定的WEB服務(wù)器一直是個(gè)熱門(mén)主題,本文就是這個(gè)主題的一次嘗試。2011-03-03
nginx設(shè)置超時(shí)時(shí)間的問(wèn)題及解決方案
程序在處理大量數(shù)據(jù),接口超過(guò)1分鐘(默認(rèn)的)未返回?cái)?shù)據(jù),導(dǎo)致等待超時(shí),出現(xiàn)這種情況,我們可以先優(yōu)化程序,縮短執(zhí)行時(shí)間,可以調(diào)大nginx超時(shí)限制的參數(shù),使程序可以正常執(zhí)行,本文介紹nginx設(shè)置超時(shí)時(shí)間及504 Gateway Time-out的問(wèn)題解決方案,一起看看吧2024-02-02
講解Nginx服務(wù)器中設(shè)置本地瀏覽器緩存的簡(jiǎn)單方法
這篇文章主要介紹了Nginx服務(wù)器中設(shè)置本地瀏覽器緩存的簡(jiǎn)單方法,需要的朋友可以參考下2015-12-12
Nginx實(shí)現(xiàn)負(fù)載均衡和反向代理的方法
Nginx是由俄羅斯人研發(fā)的,應(yīng)對(duì)Rambler的網(wǎng)站,并且2004年發(fā)布的第一個(gè)版本,Nginx功能豐富,可作為HTTP服務(wù)器,也可作為反向代理服務(wù)器,郵件服務(wù)器,本文給大家介紹了Nginx實(shí)現(xiàn)負(fù)載均衡和反向代理的方法,需要的朋友可以參考下2024-02-02
Nginx報(bào):Nginx?-?504?Gateway?Time-out問(wèn)題解決辦法
這篇文章主要給大家介紹了關(guān)于Nginx報(bào):Nginx?-?504?Gateway?Time-out問(wèn)題的解決辦法,一般是由于程序執(zhí)行時(shí)間過(guò)長(zhǎng)導(dǎo)致響應(yīng)超時(shí),例如程序需要執(zhí)行90秒,而nginx最大響應(yīng)等待時(shí)間為30秒,這樣就會(huì)出現(xiàn)超時(shí),需要的朋友可以參考下2024-01-01
Nginx 轉(zhuǎn)發(fā)匹配規(guī)則的實(shí)現(xiàn)
這篇文章主要介紹了Nginx 轉(zhuǎn)發(fā)匹配規(guī)則的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
nginx的配置轉(zhuǎn)發(fā)到其他網(wǎng)站詳解
這篇文章主要為大家介紹了nginx的配置轉(zhuǎn)發(fā)到其他網(wǎng)站過(guò)程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08

