安裝pcre依賴軟件
[root@ubuntu ~]# yum install -y pcre pcre-devel //外網(wǎng)情況使用此安裝方式
[root@ubuntu ~]# rpm -ivh pcre //內(nèi)網(wǎng)情況使用此安裝方式
[root@ubuntu ~]# rpm -ivh pcre-devel //內(nèi)網(wǎng)情況使用此安裝方式
#編譯安裝pcre依賴軟件(注意編譯安裝軟件包需要開發(fā)工具的支持安裝nginx需要make、gcc、c 支持)
#下載地址: https://ftp.pcre.org/pub/pcre/ //根據(jù)相關(guān)情況進(jìn)行選擇版本下載
[root@ubuntu ~]# wget https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz //下載pcre軟件包
[root@ubuntu ~]# tar zxf pcre-7.80.tar.gz //解壓軟件包
[root@ubuntu ~]# cd pcre-7.80 //進(jìn)入相關(guān)目錄
[root@ubuntu ~]# ./configure //配置
[root@ubuntu ~]# make && make install //編譯并編譯部署
安裝openssl依賴軟件
[root@ubuntu ~]# yum install -y openssl openssl-devel //外網(wǎng)情況使用此安裝方式
[root@ubuntu ~]# rpm -ivh openssl //內(nèi)網(wǎng)情況使用此安裝方式
[root@ubuntu ~]# rpm -ivh openssl-devel //內(nèi)網(wǎng)情況使用此安裝方式
#編譯安裝與pcre幾乎一致,請參考上一小節(jié)
安裝Nginx
nginx下載地址:nginx官網(wǎng)地址,下載nginx時需要注意版本問題,nginx分為三個版本:穩(wěn)定版、開發(fā)版和老版本穩(wěn)定版
檢查依賴是否安裝
[root@ubuntu ~]# rpm -qa pcre-devel pcre
pcre-devel-7.8-6.el6.x86_64 #pcre的devel字符串包已經(jīng)安裝
pcre-7.8-6.el6.x86_64 #pcre軟件包已經(jīng)安裝
[root@ubuntu ~]# rpm -qa openssl-devel openssl
openssl-1.0.1e-30.el6.x86_64 #openssl的包已經(jīng)安裝
openssl-devel-1.1.13-30.el6.x86_64 #openssl的devel字符串包已經(jīng)安裝
安裝nginx
[root@ubuntu:/opt]# wget -q http://nginx.org/download/nginx-1.17.6.tar.gz //下載軟件包
[root@ubuntu:/opt]# ls nginx-1.17.6.tar.gz //查看是否下載成功
-rw-r--r-- 1 root root 1037527 Nov 19 14:25 nginx-1.17.6.tar.gz
[root@ubuntu:/opt]# useradd nginx -s /sbin/nologin -M //創(chuàng)建nginx執(zhí)行用戶
[root@ubuntu:/opt]# tar xf nginx-1.17.6.tar.gz //解壓nginx軟件包
[root@ubuntu:/opt]# cd nginx-1.17.6 //進(jìn)入解壓目錄
[root@ubuntu nginx-1.17.6]#./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module //配置nginx軟件包
#具體配置模塊講解請移步nginx編譯配置模塊大全
[root@ubuntu nginx-1.17.6]# make //編譯nginx軟件包
[root@ubuntu nginx-1.17.6]# make install //部署nginx軟件包
啟動nginx檢查是否安裝成功
檢查nginx語法
root@ubuntu:~# /usr/local/nginx/sbin/nginx -t //查看nginx配置文件是否正確
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok //表示語法正確
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful //test成功
啟動nginx
root@ubuntu:~# /usr/local/nginx/sbin/nginx //直接啟動就可以
具體的啟動方式請移步:nginx部署
查看Nginx端口是否啟動
root@ubuntu:~# lsof -i :80 //查看相關(guān)端口
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 23658 root 6u IPv4 98258 0t0 TCP *:http (LISTEN)
nginx 23659 nobody 6u IPv4 98258 0t0 TCP *:http (LISTEN)
root@ubuntu:~# netstat -anpl | grep nginx //查看nginx的相關(guān)端口
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23658/nginx: master
unix 3 [ ] STREAM CONNECTED 98314 23658/nginx: master
unix 3 [ ] STREAM CONNECTED 98315 23658/nginx: master
root@ubuntu:~#
訪問nginx
root@ubuntu:~# curl 127.0.0.1 //訪問nginx
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h2>Welcome to nginx!</h2>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href=http://nginx.org/>nginx.org</a>.<br/>
Commercial support is available at
<a href=http://nginx.com/>nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
nginx目錄結(jié)構(gòu)說明
root@ubuntu:~# tree /usr/local/nginx/
/usr/local/nginx/
├── client_body_temp
├── conf #存放一系列配置文件的目錄
│ ├── fastcgi.conf #fastcgi程序相關(guān)配置文件
│ ├── fastcgi.conf.default #fastcgi程序相關(guān)配置文件備份
│ ├── fastcgi_params #fastcgi程序參數(shù)文件
│ ├── fastcgi_params.default #fastcgi程序參數(shù)文件備份
│ ├── koi-utf #編碼映射文件
│ ├── koi-win #編碼映射文件
│ ├── mime.types #媒體類型控制文件
│ ├── mime.types.default #媒體類型控制文件備份
│ ├── nginx.conf #主配置文件
│ ├── nginx.conf.default #主配置文件備份
│ ├── scgi_params #scgi程序相關(guān)配置文件
│ ├── scgi_params.default #scgi程序相關(guān)配置文件備份
│ ├── uwsgi_params #uwsgi程序相關(guān)配置文件
│ ├── uwsgi_params.default #uwsgi程序相關(guān)配置文件備份
│ └── win-utf #編碼映射文件
├── fastcgi_temp #存放fastcgi程序臨時文件
├── html #存放網(wǎng)頁文檔
│ ├── 50x.html #錯誤頁碼顯示網(wǎng)頁文件
│ └── index.html #網(wǎng)頁的首頁文件
├── logs #存放nginx的日志文件
│ ├── access.log #默認(rèn)訪問日志
│ ├── error.log #錯誤日志
│ └── nginx.pid #nginx pid文件
├── proxy_temp #代理相關(guān)臨時文件
├── sbin #存放啟動程序
│ └── nginx #nginx啟動程序
├── scgi_temp #存放scgi程序臨時文件
└── uwsgi_temp #存放uwsgi程序臨時文件
9 directories, 21 files
主配置文件說明
#user nobody; //定義執(zhí)行nginx程序的用戶
worker_processes 1; #指定nginx進(jìn)程數(shù)
#錯誤日志定義類型有:debug、info、notice、warn、error、crit
#error_log logs/error.log; //指定錯誤日志目錄
#error_log logs/error.log notice; //指定notice類型的錯誤日志目錄
#error_log logs/error.log info; //指定全局錯誤日志目錄
#worker_rlimit_nofile 1024; //指定但進(jìn)程最多打開文件數(shù)量
#pid logs/nginx.pid; //指定進(jìn)程文件的目錄
events { #事件區(qū)塊
#事件模型有:kqueue、rtsig、epoll、/dev/poll、select、poll
use epoll; #指定參考事件模型
worker_connections 1024; #指定單進(jìn)程最大鏈接數(shù)
}
http { #http區(qū)塊
include mime.types; #指定nginx支持的媒體類型
default_type application/octet-stream; #指定默認(rèn)的媒體類型
#指定日志記錄格式
#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; //指定nginx的訪問日志目錄
sendfile on; #開啟高效的傳輸模式
#tcp_nopush on; //防止網(wǎng)絡(luò)阻塞
#keepalive_timeout 0; //鏈接超時事件
keepalive_timeout 65;
#gzip on; //開啟gzip壓縮輸出
#gzip_min_length 1k; //最小壓縮文件大小
#gzip_buffers 4 16k; //壓縮緩沖區(qū)
#gzip_http_version 1.0; //壓縮版本(默認(rèn)1.1,前端如果是squid2.5請使用1.0)
#gzip_comp_level 2; //壓縮等級
#gzip_types text/x-javascript text/css application/xml; //壓縮類型,默認(rèn)就已經(jīng)包含text/html,所以下面就不用再寫了,寫上去也不會有問題,但是會有一個warn。
#gzip_vary on; //增加響應(yīng)頭”Vary: Accept-Encoding”
#limit_zone crawler $binary_remote_addr 10m; //開啟限制IP連接數(shù)的時候需要使用
#FastCGI程序相關(guān)參數(shù)
#配置FastCGI程序相關(guān)參數(shù)是為了改善網(wǎng)站的性能:減少資源占用,提高訪問速度。
#fastcgi_connect_timeout 300; //連接到后端fastcgi超時時間
#fastcgi_send_timeout 300; //向fastcgi請求超時時間(這個指定值已經(jīng)完成兩次握手后向fastcgi傳送請求的超時時間)
#fastcgi_read_timeout 300; //接收fastcgi應(yīng)答超時時間,同理也是2次握手后
#fastcgi_buffer_size 64k; //讀取fastcgi應(yīng)答第一部分需要多大緩沖區(qū),該值表示使用1個64kb的緩沖區(qū)讀取應(yīng)答第一部分(應(yīng)答頭),可以設(shè)置為fastcgi_buffers選項(xiàng)緩沖區(qū)大小
#fastcgi_buffers 4 64k; //指定本地需要多少和多大的緩沖區(qū)來緩沖fastcgi應(yīng)答請求,假設(shè)一個php或java腳本所產(chǎn)生頁面大小為256kb,那么會為其分配4個64kb的緩沖來緩存;若頁面大于256kb,那么大于的256kb的部分會緩存到fastcgi_temp指定路徑中,這并非是個好辦法,內(nèi)存數(shù)據(jù)處理快于硬盤,一般該值應(yīng)該為站點(diǎn)中php/java腳本所產(chǎn)生頁面大小中間值,如果站點(diǎn)大部分腳本所產(chǎn)生的頁面大小為256kb,那么可把值設(shè)置為16 16k,4 64k等
#fastcgi_busy_buffers_size 128k; //默認(rèn)值是fastcgi_buffer的2倍
#fastcgi_temp_file_write_size 128k; //寫入緩存文件使用多大的數(shù)據(jù)塊,默認(rèn)值是fastcgi_buffer的2倍
#fastcgi_cache TEST; //開啟fastcgi緩存并為其指定為TEST名稱,降低cpu負(fù)載,防止502錯誤發(fā)生.
#應(yīng)答代碼緩存時間,200和302應(yīng)答緩存為1個小時,301一天,其他1分鐘
#fastcgi_cache_valid 200 302 1h;
#fastcgi_cache_valid 301 1d;
#fastcgi_cache_valid any 1m;
#主機(jī)配置
server { #server區(qū)塊,每一個區(qū)塊表示一個虛擬主機(jī)
listen 80; #偵聽端口
server_name localhost; #配置此主機(jī)的域名
#charset koi8-r; //配置字符編碼
#access_log logs/host.access.log main; //配置默認(rèn)訪問日志目錄
location / { #location區(qū)塊 通過指定模式來與客戶端請求的URI相匹配
root html; #配置站點(diǎn)根目錄
index index.html index.htm; #默認(rèn)文件
}
#error_page 404 /404.html; //當(dāng)發(fā)生404錯誤的時候能夠顯示一個預(yù)定義的uri
# redirect server error pages to the static page /50x.html //將服務(wù)器錯誤頁重定向到靜態(tài)頁/50x.html
#
error_page 500 502 503 504 /50x.html; #當(dāng)發(fā)生其中錯誤的時候能夠顯示一個預(yù)定義的uri
#反向代理
#location / {
#proxy_pass http://127.0.0.1:88; //指定代理地址
#proxy_redirect off; //當(dāng)上游服務(wù)器返回的響應(yīng)是重定向或刷新請求(如HTTP響應(yīng)碼是301或者302)時,proxy_redirect可以重設(shè)HTTP頭部的location或refresh字段??蛇x參數(shù)default、off、redirect replacement]
#后端的Web服務(wù)器可以通過X-Forwarded-For獲取用戶真實(shí)IP
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $host; //允許重新定義或者添加發(fā)往后端服務(wù)器的請求頭
#client_max_body_size 10m; //允許客戶端請求的最大單文件字節(jié)數(shù)
#client_body_buffer_size 128k; //緩沖區(qū)代理緩沖用戶端請求的最大字節(jié)數(shù)
#proxy_connect_timeout 90; //nginx跟后端服務(wù)器連接超時時間(代理連接超時)
#proxy_send_timeout 90; //后端服務(wù)器數(shù)據(jù)回傳時間(代理發(fā)送超時)
#proxy_read_timeout 90; //連接成功后,后端服務(wù)器響應(yīng)時間(代理接收超時)
#proxy_buffer_size 4k; //設(shè)置代理服務(wù)器(nginx)保存用戶頭信息的緩沖區(qū)大小
#proxy_buffers 4 32k; //proxy_buffers緩沖區(qū),網(wǎng)頁平均在32k以下的設(shè)置
#proxy_busy_buffers_size 64k; //高負(fù)荷下緩沖大?。╬roxy_buffers*2)
#proxy_temp_file_write_size 64k; //設(shè)定緩存文件夾大小,大于這個值,將從upstream服務(wù)器傳
106
#}
#設(shè)置js和css緩存時間
#location ~ .*\\\\.(js|css)?$
#{
#expires 2h;
# }
#設(shè)置圖片緩存事件
#location ~ .*\\\\.(gif|jpg|jpeg|png|bmp|swf)$
#{
#expires 5d;
# }
#監(jiān)控Nginx狀態(tài)的地址
#location /NginxStatus {
#stub_status on; //開啟監(jiān)控狀態(tài)
#access_log on; //開啟默認(rèn)訪問監(jiān)控
#auth_basic NginxStatus; //設(shè)置驗(yàn)證模塊
#auth_basic_user_file conf/htpasswd; //htpasswd文件的內(nèi)容可以用apache提供的htpasswd工具來產(chǎn)生。
#}
#動靜分離配置
#所有jsp的頁面均交由tomcat處理
#location ~ .(jsp|jspx|do)?$ {
#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_pass http://127.0.0.1:8080;
# }
#所有靜態(tài)文件由nginx直接讀取不經(jīng)過tomcat
#location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$#
#{
#expires 10d;
#}
#location ~ .*.(js|css)?${
#expires 2h;
#}
}
更多關(guān)于云服務(wù)器,域名注冊,虛擬主機(jī)的問題,請?jiān)L問西部數(shù)碼官網(wǎng):www.ps-sw.cn