新聞中心
2.安裝openssl-fips-2.0.9.tar.gz,執(zhí)行命令如下:
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協(xié)議,并提供豐富的應(yīng)用程序供測試或其它目的使用。,安裝OpenSSL(http://www.openssl.org/source/)主要是為了讓tengine支持Https的訪問請求。具體是否安裝看需求。

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司10余年經(jīng)驗成就非凡,專業(yè)從事成都做網(wǎng)站、成都網(wǎng)站制作,成都網(wǎng)頁設(shè)計,成都網(wǎng)頁制作,軟文平臺,一元廣告等。10余年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:13518219792,我們期待您的來電!
cd /home/nginx_install
tar -zxvf openssl-1.0.2o.tar.gz
cd openssl-1.0.2o
#prefix配置安裝路徑
./config --prefix=/opt/ldkjdata/nginx/openssl-1.0.2o
make
make install
openssl:wget http://www.openssl.org/source/openssl-0.9.8m.tar.gz 解壓不make
最新版本為openssl-1.0.2o.tar
3.安裝zlib-1.2.8.tar.gz
Zlib是提供資料壓縮之用的函式庫,當Tengine想啟用GZIP壓縮的時候就需要使用到Zlib(http://www.zlib.net/)
cd /home/nginx_install
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/opt/ldkjdata/nginx/zlib-1.2.11
make
make install
4.安裝pcre-8.37.tar.gz
PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx rewrite依賴于PCRE庫,所以在安裝Tengine前一定要先安裝PCRE,最新版本的PCRE可在官網(wǎng)(http://www.pcre.org/)獲取。
cd /home/nginx_install
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42
./configure --prefix=/opt/ldkjdata/nginx/pcre-8.42
make
make install
5.安裝nginx-1.8.0.tar.gz
cd /home/nginx_install
tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
#with-pcre指定依賴包位置,prefix配置安裝路徑
./configure --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-fips-2.0.16 --prefix=/opt/ldkjdata/nginx/nginx-1.14.0
或者
./configure --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2o --with-http_ssl_module --prefix=/opt/ldkjdata/nginx/nginx-1.14.0
make
make install
3、Nginx檢測
cd /opt/ldkjdata/nginx/nginx-1.14.0/sbin
./nginx -t
看到如下提示,表示安裝成功。
nginx: the configuration file /opt/ldkjdata/nginx/nginx-1.14.0/conf/nginx.conf syntax is ok
nginx: configuration file /opt/ldkjdata/nginx/nginx-1.14.0/conf/nginx.conf test is successful
4.Nginx啟動和端口查看
cd /opt/ldkjdata/nginx/nginx-1.14.0/sbin
./nginx 啟動
./nginx -s stop 停止
./nginx -s reload 修改配置后重新加載配置
netstat -ntlp 查看tcp是否正常監(jiān)聽
5.一個簡單的Nginx轉(zhuǎn)發(fā)例子
1.需求
短信服務(wù)器列表三臺,提供服務(wù)的地址如下:
http://192.168.88.21:8091/smsserver/services/sendSms?wsdl
http://192.168.88.22:8091/smsserver/services/sendSms?wsdl
http://192.168.88.23:8091/smsserver/services/sendSms?wsdl
彩信服務(wù)器列表三臺,提供服務(wù)的地址如下:
http://192.168.88.21:8092/msserver/services/sendMms?wsdl
http://192.168.88.22:8092/mmsserver/services/sendMms?wsdl
http://192.168.88.23:8092/mmsserver/services/sendMms?wsdl
Nginx安裝在另外一臺單獨機器上(公網(wǎng)IP為public_ip),對外提供服務(wù)地址如下:
http://public_ip:8090/smsserver/services/sendSms?wsdl 短信發(fā)送服務(wù)
http://public_ip:8090/mmsserver/services/sendMms?wsdl 彩信發(fā)送服務(wù)
2.對于以上需求,配置/opt/nginx-1.8.0/conf/nginx.conf如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#設(shè)定請求緩沖, start
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#設(shè)定請求緩沖, end
#設(shè)定提供服務(wù)的服務(wù)器,start
#短信發(fā)送服務(wù)器
upstream smsserver{
#weigth 表示權(quán)重,權(quán)值越大,分配幾率越大
#max_fails 當有max_fails個請求失敗,就表示后端的服務(wù)器不可用,默認為1,將其設(shè)置為0可以關(guān)閉檢查
#fail_timeout 在以后的fail_timeout時間內(nèi)nginx不會再把請求發(fā)往已檢查出標記為不可用的服務(wù)器
server 192.168.88.21:8091 weight=5 max_fails=5 fail_timeout=600s;
server 192.168.88.22:8091 weight=5 max_fails=5 fail_timeout=600s;
server 192.168.88.23:8091 weight=5 max_fails=5 fail_timeout=600s;
}
#彩信發(fā)送服務(wù)器
upstream mmsserver{
#weigth 表示權(quán)重,權(quán)值越大,分配幾率越大
#max_fails 當有max_fails個請求失敗,就表示后端的服務(wù)器不可用,默認為1,將其設(shè)置為0可以關(guān)閉檢查
#fail_timeout 在以后的fail_timeout時間內(nèi)nginx不會再把請求發(fā)往已檢查出標記為不可用的服務(wù)器
server 192.168.88.21:8092 weight=5 max_fails=5 fail_timeout=600s;
server 192.168.88.22:8092 weight=5 max_fails=5 fail_timeout=600s;
server 192.168.88.23:8092 weight=5 max_fails=5 fail_timeout=600s;
}
#設(shè)定提供服務(wù)的服務(wù)器,end
#gzip on;
server {
listen 8090;
server_name localhost;
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, start
#規(guī)則采用最長匹配,/smsserver/*優(yōu)先匹配/smsserver,/mmsserver/*優(yōu)先匹配/mmsserver,/aaaaaaaa/*因為沒有任何匹配,最后匹配到/
#規(guī)則一
location / {
proxy_pass http://localhost:80;
}
#規(guī)則二
location /smsserver {
proxy_pass http://smsserver;
}
#規(guī)則三
location /mmsserver {
proxy_pass http://mmsserver;
}
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, end
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name localhost;
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, start
location / {
#定義服務(wù)器的默認網(wǎng)站根目錄位置
root /home/work/statichtml/index.html;
#定義首頁索引文件的名稱
#index index.php index.html index.htm;
#請求轉(zhuǎn)向orderServer定義的服務(wù)器列表
# proxy_pass http://server;
#以下是一些反向代理的配置可刪除.
# 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;
#允許客戶端請求的最大單文件字節(jié)數(shù)
# client_max_body_size 10m;
#緩沖區(qū)代理緩沖用戶端請求的最大字節(jié)數(shù),
# client_body_buffer_size 128k;
#nginx跟后端服務(wù)器連接超時時間(代理連接超時)
# proxy_connect_timeout 90;
#后端服務(wù)器數(shù)據(jù)回傳時間(代理發(fā)送超時)
# proxy_send_timeout 90;
#連接成功后,后端服務(wù)器響應(yīng)時間(代理接收超時)
# proxy_read_timeout 90;
#設(shè)置代理服務(wù)器(nginx)保存用戶頭信息的緩沖區(qū)大小
# proxy_buffer_size 4k;
#proxy_buffers緩沖區(qū),網(wǎng)頁平均在32k以下的話,這樣設(shè)置
# proxy_buffers 4 32k;
#高負荷下緩沖大?。╬roxy_buffers*2)
# proxy_busy_buffers_size 64k;
#設(shè)定緩存文件夾大小,大于這個值,將從upstream服務(wù)器傳
# proxy_temp_file_write_size 64k;
}
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, end
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
6.例子2(暴露接口,但隱藏web項目的根目錄)
上面6中例子有個問題是,直接將我整個web根目錄smsserver和mmsserver暴露到公網(wǎng)了,其實我的目的只是想暴露兩個接口地址,所以6有待優(yōu)化,舉個例子如下:
1.需求
接口服務(wù)器列表兩臺臺,提供服務(wù)的地址如下:
接口一:
http://192.168.88.21:8082/myweb/interface/getData
http://192.168.88.22:8082/myweb/interface/getData
接口二:
http://192.168.88.21:8082/myweb/interface/sendData
http://192.168.88.22:8082/myweb/interface/sendData
Nginx安裝在另外一臺單獨機器上(公網(wǎng)IP為public_ip),對外提供服務(wù)地址如下:
http://public_ip:8081/myweb/interface/getData 接口一
http://public_ip:8081/myweb/interface/sendData 接口二
2.對于以上需求,配置/opt/nginx-1.8.0/conf/nginx.conf如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#設(shè)定請求緩沖, start
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#設(shè)定請求緩沖, end
#設(shè)定提供服務(wù)的服務(wù)器,start
#我的接口服務(wù)器,兩臺
upstream myweb{
#weigth 表示權(quán)重,權(quán)值越大,分配幾率越大
#max_fails 當有max_fails個請求失敗,就表示后端的服務(wù)器不可用,默認為1,將其設(shè)置為0可以關(guān)閉檢查
#fail_timeout 在以后的fail_timeout時間內(nèi)nginx不會再把請求發(fā)往已檢查出標記為不可用的服務(wù)器
server 192.168.88.23:8082 weight=5 max_fails=5 fail_timeout=600s;
server 192.168.88.24:8082 weight=5 max_fails=5 fail_timeout=600s;
}
#設(shè)定提供服務(wù)的服務(wù)器,end
#gzip on;
server {
listen 80;
server_name localhost;
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, start
#規(guī)則采用最長匹配,即長度最長優(yōu)先匹配,最后不匹配的走/進行匹配
#規(guī)則一
location / {
root html;
index index.html index.htm;
}
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, end
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8081;
server_name localhost;
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, start
#規(guī)則采用最長匹配,即長度最長優(yōu)先匹配,最后不匹配的走/進行匹配
#規(guī)則一
location / {
root html;
index index.html index.htm;
}
#規(guī)則二,查詢接口一
location /myweb/interface/getData {
proxy_pass http://myweb;
#轉(zhuǎn)發(fā)請求的原IP地址,程序中通過request.getHeader("Proxy-Client-IP")獲得ip
proxy_set_header Host $host;
#如果是有涉及redirect的服務(wù),一定要加上端口8081,否則默認tomcat在redirect時候默認找80端口
#proxy_set_header Host $host:8081;
proxy_set_header Proxy-Client-IP $remote_addr;
}
#規(guī)則三,查詢接口二
location /myweb/interface/sendData {
proxy_pass http://myweb;
#轉(zhuǎn)發(fā)請求的原IP地址,程序中通過request.getHeader("Proxy-Client-IP")獲得ip
proxy_set_header Host $host;
#如果是有涉及redirect的服務(wù),一定要加上端口8081,否則默認tomcat在redirect時候默認找80端口
#proxy_set_header Host $host:8081;
proxy_set_header Proxy-Client-IP $remote_addr;
}
#設(shè)定請求轉(zhuǎn)發(fā)規(guī)則, end
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
7.例子3 文件映射
/conf/nginx.conf中第一行的運行用戶改為
user root;
location /uploadfile {
root /opt/staticdata/;
access_log /opt/nginx/logs/upload_access.log;
proxy_store_access user:rw group:rw all:rw;
}
當訪問http://ip:port/uploadfile/aa/bb/cc.jpg
相當于訪問 /opt/staticdata/uploadfile/aa/bb/cc.jpg
分享題目:CentOS7下Nginx安裝部署和配置
當前URL:http://m.fisionsoft.com.cn/article/dphessj.html


咨詢
建站咨詢
