day12-nginx

nginx

前臺服務器并發大

安裝nginx

useradd –s /sbin/nologin nginx

tar xf nginx-xxx.tar.gz

yum install –y gcc pcre-devel openssl-devel

./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

 1 nginx path prefix: "/etc/nginx"
 2 
 3 nginx binary file: "/etc/nginx/sbin/nginx"
 4 
 5 nginx modules path: "/etc/nginx/modules"
 6 
 7 nginx configuration prefix: "/etc/nginx/conf"
 8 
 9 nginx configuration file: "/etc/nginx/conf/nginx.conf"
10 
11 nginx pid file: "/etc/nginx/logs/nginx.pid"
12 
13 nginx error log file: "/var/log/nginx/error.log"
14 
15 nginx http access log file: "/var/log/nginx/access.log"
16 
17 nginx http client request body temporary files: "client_body_temp"
18 
19 nginx http proxy temporary files: "proxy_temp"
20 
21 nginx http fastcgi temporary files: "fastcgi_temp"
22 
23 nginx http uwsgi temporary files: "uwsgi_temp"
24 
25 nginx http scgi temporary files: "scgi_temp"
26 
27 make && make install

?

注意:默認該軟件不提供啟動腳本

? ?

nginx配置文件及目錄

/etc/nginx????????安裝目錄

/etc/nginx/conf/nginx.conf????????主配置文件

/etc/nginx/html????????網頁目錄

/etc/nginx/logs????????日志文件

sbin/nginx????????啟動腳本

? ?

啟動nginx服務

-v????查看nginx

-V????查看編譯參數

-t????測試默認配置文件

-c????指定配置文件

?

[root@localhost sbin]# ./nginx -v

nginx version: nginx/1.10.1

[root@localhost sbin]# ./nginx -V

nginx version: nginx/1.10.1

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)

built with OpenSSL 1.0.0-fips 29 Mar 2010

TLS SNI support enabled

configure arguments: --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

[root@localhost sbin]# ./nginx -t

nginx: the configuration file /etc/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/conf/nginx.conf test is successful

?

停止nginx

格式:pkill/kill????信號????進程名/pid號

常用信號

TERM,INT????快速關閉

QUIT????從容關閉,關閉主進程順便關閉工作子進程

HUP????重載配置用新的配置????????相當于服務reload,服務不關閉,重新讀取配置文件

kill -HUP `cat /var/run/nginx.pid`

USR1????重新打開日志文件

USR2????平滑升級可執行程序????????服務不關閉,升級程序

WINCH????從容關閉工作進程,不會立即關閉子進程

? ?

可使用kill –l 查看

kill????PID????????默認是????15) SIGTERM

kill????-9????為????9) SIGKILL????

ctrl+c????為????2) SIGINT

? ?

/usr/local/nginx/sbin/nginx????????開啟服務

/usr/local/nginx/sbin/nginx –s stop????關閉服務

? ?

升級nginx

[root@localhost sbin]# /etc/nginx/sbin/nginx -V

nginx version: nginx/1.10.1

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)

built with OpenSSL 1.0.0-fips 29 Mar 2010

TLS SNI support enabled

configure arguments: --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

?

tar xf nginx-xxx1.tar.gz

./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

make

cd /etc/nginx/sbin

mv nginx nginxold????備份以前版本的nginx程序

cd nginx/objs????打開新版本的nginx目錄下的objs

[root@localhost nginx-1.11.4]# cp objs/nginx /etc/nginx/sbin/nginx????復制新版本的nginx程序

cd ..

make upgrade

[root@localhost ~]# /etc/nginx/sbin/nginx -v

nginx version: nginx/1.11.4

?

主配置選項:

 1 user nginx        進程所有者
 2 
 3 worker_processes 1;    啟動進程數量,(推薦:最好等于CPU核心的數量)
 4 
 5 error_log /var/log/nginx/error.log;    日志文件
 6 
 7 pid    /var/run/nignx.pid;    PID文件
 8 
 9 events {    
10 
11     use epoll;
12 
13     worker_connections    1024;        單個進程最大并發量
14 
15 }
16 
17 keepalive_timeout 65    保持連接,超時時間
18 
19 tcp_nodelay    on;    禁用nagle        禁用延遲.無等待(要求并發量高,設置)
20 
21 gzip    on;    開啟gzip壓縮        提高速度
22 
23 gzip_min_length    1000;    最小壓縮文件大小
24 
25 gzip_disable "MISE[1-6]\.(?!.*SV1)";    針對IE禁用gzip
26 
27    
28 
29 server{        定義虛擬主機
30 
31     listen 80;
32 
33     server_name web1.myweb.com;
34 
35     location / {    發布目錄    相當于http://192.168.100.100/根下
36 
37         root html;
38 
39         index index.html index.htm index.php;
40 
41         allow 192.168.100.101;        只允許192.168.100.101訪問
42 
43         deny all;
44 
45         auth_basic "auth-domain";            //開啟賬戶驗證
46 
47         auth_basic_user_file /usr/local/nginx/conf/user.list;        //指定賬戶及密碼的保存文件路徑
48 
49 }
50 
51 }

?

? ?

創建密碼文件:

yum install -y

yum whatprovides /usr/bin/htpasswd ????????查看這條命令來自哪個包

htpasswd –c /etc/nginx/conf/user.list 用戶名????第一次創建加-c選項 下次創建用戶無需加c

htpasswd /etc/nginx/conf/user.list用戶名

可以對密碼進行加密

htpasswd –cm /usr/local/nginx/conf/ user.list 用戶名

? ?

?

啟動腳本(簡單實現功能,以后會改善)

 1 #!/bin/bash
 2 
 3 # chkconfig: - 85 15
 4 
 5 case "$1" in
 6 
 7 start)
 8 
 9 /etc/nginx/sbin/nginx
10 
11 echo "$0:nginx ok..."
12 
13 ;;
14 
15 stop)
16 
17 /etc/nginx/sbin/nginx -s stop
18 
19 #kill -INT `cat /var/run/nginx.pid`
20 
21 echo "$0:nginx stop..."
22 
23 ;;
24 
25 reload)
26 /etc/nginx/sbin/nginx -s reload
27 #kill -HUP `cat /var/run/nginx.pid`
28 
29 echo "$0:nginx reload..."
30 
31 ;;
32 
33 *)
34 
35 echo "$0:start|stop|restart|reload"
36 
37 esac

?

?

虛擬主機

 1 server{
 2 
 3 listen 80;
 4 
 5 server_name www.web1.com;
 6 
 7 location / {
 8 
 9 root web1;
10 
11 index index.html index.htm;
12 
13 }
14 
15 }
16 
17 server{
18 
19 listen 80;
20 
21 server_name www.web2.com;
22 
23 location / {
24 
25 root web2;
26 
27 index index.html;
28 
29 }

?

?

基于SSL的網站

加密算法:對稱加密,非對稱加密

基于SSL的網站基于非對稱加密算法

需要生產:私鑰、證書

生產私鑰和證書

# openssl genrsa -out cert.key 2048????????????

生成密鑰,gen后面是RSA算法,cret.key是文件名字

# openssl req -new -x509 -key cert.key -out cert.pem????用私鑰生成證書

[root@localhost nginx]# ls cert.*

cert.key cert.pem

?

# cp cert.* /etc/nginx/conf  默認放在nginx/conf目錄下

?配置文件

?

 1     keepalive_timeout  65;2     gzip  on;3     gzip_min_length 1000;4     gzip_disable "MISE[1-6]\.(?!.*SV1)";5         server{6                 listen 80;7                 server_name www.web1.com;8                 location / {9                         root web1;
10                         index index.html index.htm;
11 #                       auth_basic "auth-domain";
12 #                       auth_basic_user_file /etc/nginx/conf/user.list;
13                 }
14         }
15 
16 #user  nobody;
17 user nginx;
18 worker_processes  1;
19 error_log  /var/log/nginx/error.log;
20 #error_log  logs/error.log  notice;
21 #error_log  logs/error.log  info;
22 pid        /var/run/nginx.pid;
23 events {
24     use epoll;
25     worker_connections  1024;
26 }
27 http {
28     include       mime.types;
29     default_type  application/octet-stream;
30     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
31     #                  '$status $body_bytes_sent "$http_referer" '
32     #                  '"$http_user_agent" "$http_x_forwarded_for"';
33     #access_log  logs/access.log  main;
34     sendfile        on;
35     tcp_nopush     on;
36     #keepalive_timeout  0;
37         server{
38                 listen 80;
39                 server_name www.web2.com;
40                 location / {
41                 root web2;
42                 index index.html;
43                 }
44         }
45 
46 server {
47         listen 443;
48         server_name www.web3.com;
49         ssl  on;
50         ssl_certificate      cert.pem;
51         ssl_certificate_key  cert.key;
52         location / {
53                 root web3;
54                 index index.html;
55         }}
56         server {
57         listen 443;
58         server_name www.web4.com;
59         ssl  on;
60         ssl_certificate      /etc/nginx/ssl/test.pem;
61         ssl_certificate_key  /etc/nginx/ssl/test.key;
62         location / {
63                 root web4;
64                 index index.html;
65         }
66         }
67 }

?

nginx反向代理

優勢:調度快,調試機制豐富

缺點:ACL訪問控制簡單(沒有SQUID功能多),緩存機制

主服務配置文件

upstream test {server 192.168.100.101;server 192.168.100.102;
}
server {listen 80;server_name www.test.com;location / {proxy_pass http://test;
        }
}

?

其他兩臺192.168.100.101和102,開啟WEB服務即可

?客戶端驗證

這是輪詢訪問

?

nginx目前支持4種分配方式

輪詢(默認)逐一手循環調度

weight指定輪詢機率,權重值和訪問比率正比

ip_hash每個請求根據訪問IP分配一個固定t后端服務器

fair按后端服務器響應時間短的優先分配

狀態類型

down:表示當前server暫時不參與負載

max_fails:允許請求失敗的次數(默認為1)

fail_timeout:max_fails次失敗后,暫停提供服務時間

backup:備份服務器

?

當server 192.168.100.101 weight=2;改為

驗證

?

 1 upstream test {
 2         ip_hash;    給同一用戶分配固定服務器
 3         server 192.168.100.101 weight=2;權重為2
 4         server 192.168.100.102 max_fails=2 fail_timeout=30;如何該地址有三次連接失敗,則宕機30秒
 5         server 192.168.100.103 down; 宕機服務器
 6         server 192.168.100.104 backup;備份服務器 (當前面的服務器都宕機才會啟用)
 7 }
 8 server {
 9         listen 80;
10         server_name www.test.com;
11         location / {
12                 proxy_pass http://test;
13         }
14 }

?

轉載于:https://www.cnblogs.com/fina/p/5886008.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/260557.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/260557.shtml
英文地址,請注明出處:http://en.pswp.cn/news/260557.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python args_Python可變參數*args和**kwargs用法實例小結

本文實例講述了Python可變參數*args和**kwargs用法。分享給大家供大家參考,具體如下: 一句話簡單概括:當函數的參數不確定的時候就需要用到*args和**kwargs,前者和后者的區別在于,后者引入了”可變”key的概念&#xf…

文件組備份還原

-- 參考 USE master; GO-- 測試的DB CREATE DATABASE DB_Test ON PRIMARY(NAME DB_Test,FILENAME C:\DB_Test.mdf ), FILEGROUP FG1 (NAME DB_Test_FG1,FILENAME C:\DB_Test_fg1.ndf ), FILEGROUP FG2 (NAME DB_Test_FG2,FILENAME C:\DB_Test_fg2.ndf ) LOG ON(NAME DB_…

php調用c++

1.在/var/www中建個測試文件夾 cpp 在此文件夾中新建c文件sort.cpp,如下 編譯并測試執行通過進行以下步驟。 2.在cpp文件夾下新建文件cpp.html,如下 3.同樣在cpp下建php文件cpp.php,如下 保存。 4.程序執行如下 提交后: 轉載于:ht…

AI+無線通信——Top7 (Baseline)分享與總結

從浩哥那里轉載 https://wanghao.blog.csdn.net/article/details/115813954 比賽已經告一段落,現在我們隊兌現承諾,將比賽方案開源給大家,互勉互助,共同進步。 隊伍介紹 我們的隊伍名是Baseline,我們因分享Baseline…

拼字符串成為時間,和兩個計算時間點的中間值

拼字符串成為時間,和兩個計算時間點的中間值 select convert(datetime,2016-09-18 SUBSTRING(CONVERT(varchar(100),d_bdate, 24), 0, 9),21) from B2C_daima where d_noB04 select case when Datename(hour,d_edate)> Datename(hour,d_bdate) then convert(dat…

tornado post第3方_[33]python-Web-框架-Tornado

1.TornadoTornado:python編寫的web服務器兼web應用框架1.1.Tornado的優勢輕量級web框架異步非阻塞IO處理方式出色的抗負載能力優異的處理性能,不依賴多進程/多線程,一定程度上解決C10K問題WSGI全棧替代產品,推薦同時使用其web框架…

android 串口調試工具_樹莓派通用串口通信實驗

一、介紹對于樹莓派 3B來說,他的UART功能有三種:1、內部藍牙使用;2、控制終端使用;3、與其他設備進行串口通信。在樹莓派USB TO TTL模塊實驗中學習了通過串口對樹莓派進行控制臺控制,讓串口作為控制終端調試口即 seria…

Laravel5.2目錄結構及composer.json文件解析

目錄或文件說明|– app包含Controller、Model、路由等在內的應用目錄,大部分業務將在該目錄下進行|  |– Console命令行程序目錄|  |  |– Commands包含了用于命令行執行的類&#xff…

ichat在線客服jQuery插件(可能是歷史上最靈活的)

ichat是一款開源免費在線客服jQuery插件,通過該插件,您可以自由的定制屬于自己的在線客服代碼。 ichat充分吸收傳統在線客服插件的優點,并加上自身的獨特設計,使得ichat可定制性異常強大。 ichat追求簡單實用,走小清新…

POJ 1007 DNA Sorting

按照字符串的逆序排序。 /*Accepted 100K 16MS C 863B 2012-08-03 08:30:48*/ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; const int MAXN 55, MAXM 110; struct str {char…

第6章 Python 數字圖像處理(DIP) - 彩色圖像處理1 - RGB彩色模型,RGB to Gray,CMK和CMYK彩色模型,HSI彩色模型

第6章主要講的是彩色圖像處理&#xff0c;一些彩色模型如RGB&#xff0c;CMK&#xff0c;CMYK&#xff0c;HSI等色彩模型&#xff1b;彩色模型的變換關系&#xff1b;還包含由灰度圖像怎樣處理成假彩色圖像&#xff1b;使用彩色分割圖像等。本章比較少理論還有變換的描述&#…

git 命令詳解_再次學習Git版本控制工具

微信公眾號&#xff1a;PHP在線Git 究竟是怎樣的一個系統呢&#xff1f;為什么在SVN作為版本控制工具已經非常流行的時候&#xff0c;還有Git這樣一個版本控制工具呢&#xff1f;Git和SVN的區別在哪兒呢&#xff1f;Git優勢又在哪呢&#xff1f;下面PHP程序員雷雪松帶你一起詳細…

python twisted和flask_淺談Python Web 框架:Django, Twisted, Tornado, Flask, Cyclone 和 Pyramid...

Django 是一個高級的 Python Web 框架&#xff0c;支持快速開發&#xff0c;簡潔、實用的設計。如果你正在建一個和電子商務網站相似的應用&#xff0c;那你應該選擇用 Django 框架。它能使你快速完成工作&#xff0c;也不必擔心太多的技術選擇。它能提供從模版引擎到 ORM 所需…

spring-boot 定時任務

2019獨角獸企業重金招聘Python工程師標準>>> 1、建立項目 SpringBootApplication EnableAsync EnableScheduling EnableAutoConfiguration(exclude{ DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class}) ImportResource(…

使用Lightbox制作照片條

前言&#xff1a;這是國外的一個教程&#xff0c;我也很喜歡這個網頁里面的教程&#xff0c;主要技術是CSS3和JQuery以及一些JQuery的插件的應用&#xff0c;當然從這些教程我也學到了他們制作時的一些思路&#xff0c;就好像做數學題那樣&#xff0c;只要思路把握了&#xff0…

iOS- 如何改變section header

希望這個從UITableViewDelegate協議里得到的方法可以對你有所幫助&#xff1a; - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {UIView *headerView [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.…

第6章 Python 數字圖像處理(DIP) - 彩色圖像處理2 - 灰度分層(灰度分割)和彩色編碼,灰度值到彩色變換,Gray to RGB

第6章主要講的是彩色圖像處理&#xff0c;一些彩色模型如RGB&#xff0c;CMK&#xff0c;CMYK&#xff0c;HSI等色彩模型&#xff1b;彩色模型的變換關系&#xff1b;還包含由灰度圖像怎樣處理成假彩色圖像&#xff1b;使用彩色分割圖像等。本章比較少理論還有變換的描述&#…

值重新賦值_JavaScript-賦值運算符

好好學習&#xff0c;天天向上賦值運算符賦值運算符必須有變量參與運算&#xff0c;賦值運算符會做兩件事情第一&#xff0c;將變量中原始值參與對應數學運算&#xff0c;與右側的數據第二&#xff0c;將運算結果再重新賦值給變量變量位于操作符的左側賦值運算符符號&#xff1…

超聲換能器的原理及設計_超聲波發生器、變幅桿、焊頭的匹配介紹

一.超聲波換能器原理與設計(超聲波振動系統)匹配摘要&#xff1a;就塑料焊接機的超聲波換能器系統進行設計和計算&#xff0c;并用PRO- E 三維軟件繪出三維模型&#xff0c;最后進行頻率分析&#xff0c;為超聲波換能系統提供了有用的設計方法。關鍵詞&#xff1a;超聲波換能器…

位圖法

判斷集合中存在重復是常見編程任務之一&#xff0c;當集合中數據量比較大時我們通常希望少進行幾次掃描&#xff0c;這時雙重循環法就不可取了。位圖法比較適合于這種情況&#xff0c;它的做法是按照集合中最大元素max創建一個長度為max1的新數組&#xff0c;然后再次掃描原數組…