2.上傳nginx到linux系統
3.安裝依賴環境
無腦往下執行就ok
(1)安裝gcc環境
yum install gcc-c++
(2)安裝pcre庫,用於解析正規表示式
yum install -y pcre pcre-devel
(3)zlib壓縮和解壓縮依賴,
yum install -y zlib zlib-devel
(4)ssl 安全的加密的套接字協議層,用於http安全傳輸,也就是https
yum install -y openssl openssl-devel
(5)解壓,需要注意,解壓後得到的是原始碼,原始碼需要編譯後才能安裝我解壓到root下
tar -zxvf nginx-1.16.1.tar.gz
(6)編譯之前,先建立nginx臨時目錄,如果不建立,在啟動nginx的過程中會報錯
mkdir /var/temp/nginx -p
(7)在nginx目錄,輸入如下命令進行配置,目的是為了建立makefile檔案
--http-scgi-temp-path=/var/temp/nginx/scgi
7.make編譯
make
8.安裝
#老鳥告訴你這樣編譯的話會快一點
make -j 4 install
9.進入sbin目錄啟動nginx
./nginx
二使用
下面我們進入conf檢視ngxin.conf的核心檔案
進入到這個目錄下面
[root@huaxinfeng51 conf]# pwd
/usr/local/nginx/conf
vim命令修改配置檔案
[root@huaxinfeng51 conf]# vim nginx.conf
1.設定worker程序的使用者,指的linux中的使用者,會涉及到nginx操作目錄或檔案的一些許可權,預設為nobody,這個是你以什麼身份啟動nginx那我的話用root啟動,你也可以建立nginx使用者給nginx使用者許可權
user root;
2.worker程序工作數設定,一般來說cpu有幾個,就設定幾個,或者設定為n-1也行 或者說auto也是可以的,不過按照經驗來說你有幾個cpu就寫幾個
worker_processes 1;
3.nginx 日誌級別debug | info | notice | warn | error | crit | alert | emerg,錯誤級別從左到右越來越大
4.設定nginx程序 pid
pid /usr/local/nginx/logs/nginx.pid;
####你重啟nginx的時候很可能會報錯找不到pid那麼這個情況下你得這麼來
進入nginx安裝目錄/sbin/下執行
nginx 或者 nginx -c 特定位置的nginx.conf
nginx -c …/conf/nginx.conf
然後重啟
5.設定工作模式
events
6.http 是指令塊,針對http網路傳輸的一些指令配置
http
7.include 引入外部配置,提高可讀性,避免單個配置檔案過大,你可在conf檔案裡面看看這個檔案
include mime.types;
8.設定日誌格式,main為自定義的格式名稱,如此 access_log 就可以直接使用這個變數了
在/var/log/nginx下面這些log就是上面綠色的定義
引數名 引數意義
$remote_addr 客戶端ip
$remote_user 遠端客戶端使用者名稱,一般為:』-』
$time_local 時間和時區
$request 請求的url以及method
$status 響應狀態碼
$body_bytes_send 響應客戶端內容位元組數
$http_referer 記錄使用者從哪個鏈結跳轉過來的
$http_user_agent 使用者所使用的**,一般來時都是瀏覽器
$http_x_forwarded_for 通過**伺服器來記錄客戶端的ip
9.sendfile使用高效檔案傳輸,提公升傳輸效能。啟用後才能使用tcp_nopush,是指當資料表累積一定大小後才傳送,提高了效率
sendfile on;
tcp_nopush on;
10.keepalive_timeout設定客戶端與服務端請求的超時時間,保證客戶端多次請求的時候不會重複建立新的連線,節約資源損耗。
#keepalive_timeout 0;
keepalive_timeout 65;
12.server可以在http指令塊中設定多個虛擬主機
listen 監聽埠
server_name localhost、ip、網域名稱
location 請求路由對映,匹配攔截
root 請求位置
index 首頁設定
server
}
nginx在CentOS7中的安裝教程
系統軟體 centos 7.4 nginx軟體 linux nginx 1.16.1.tar.gz 1.安裝依賴包安裝gcc 安裝pcre 安裝zlib 安裝openssl 如果不想乙個個地安裝這些依賴包,也可以使用綜合命令yum y install gcc zlib zlib devel pcre...
在 centos7 安裝配置 nginx
centos7 nginx 1.12.2 yum install wget wget 1,解壓 nginx 到指定位置 tar zxvf nginx 1.12.2.tar.gz soft nginx 2,跳轉到 nginx 解壓目錄下,執行配置命令 configure 3,編譯安裝 yum y in...
centos7安裝nginx與nginx配置檔案
yum install gcc c nginx原始碼編譯需要 yum install y pcre pcre devel nginx 的 http 模組使用 pcre 來解析正規表示式yum install y zlib zlib devel nginx 使用zlib對http包的內容進行gzipy...