雲計算高端架構師:nginx服務器

Nginx: 是一個高性能HTTP 和 反向代理 服務器、IMAP、POP3、SMTP 郵件代理服務器。
特點: 高併發響應性能非常好,官方Nginx處理靜態文件併發5w/s;負載均衡及反向代理性能非常強;可對後端服務進行健康檢查;支持PHP cgi方式和FastCGI方式;可以作爲緩存服務器、郵件代理服務器;支持熱部署(在線升級)。
部署nginx:
yum部署:


# 配置倉庫:
// vim /etc/yum.repos.d/nginx.repo
# 安裝:
// yum install nginx -y
### 源碼部署:
下載nginx源碼包:
// wget http://nginx.org/download/nginx-1.18.0.tar.gz
# 解壓:
// tar xf nginx-1.18.0.tar.gz
# 解決依賴:
// yum install pcre-devel zlib-devel -y
# 預編譯:
cd nginx-1.18.0
// ./configure --prefix=/usr/local/nginx
# 編譯、安裝:
make && make install
# 啓動服務:
// /usr/local/nginx/sbin/nginx
# 查看進程與端口:
// ps -ef | grep nginx

nginx常用指令:

Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p
prefix] [-g directives]
Options:
-?,-h : this help
# 顯示nginx版本
-v : show version and exit
# 顯示nginx版本以及nginx預編譯參數
-V : show version and configure options then
exit
# 測試nginx配置文件語法問題
-t : test configuration and exit
# 測試nginx配置文件語法問題,並且還可以利用重定向進行配置文件備份
-T : test configuration, dump it and exit
# 靜默模式啓動nginx服務:
-q : suppress non-error messages during
configuration testing
# 給master進程發送信號,包括立即停止,優雅停止,重載日誌文件,重載配置文件。
-s signal : send signal to a master process: stop,
quit, reopen, reload
# 設置nginx主目錄:
-p prefix : set prefix path (default:
/usr/local/nginx/)
# 設置nginx啓動的配置文件
-c filename : set configuration file (default:
conf/nginx.conf)
# 設置nginx全局變量
-g directives : set global directives out of
configuration file 

配置nginx虛擬主機:
配置虛擬主機常見方式: 基於多域名配置虛擬主機; 基於多端口配置虛擬主機; 基於多IP配置虛擬主機;基於多域名配置虛擬主機

// vim /usr/local/nginx/conf/nginx.conf
...
keepalive_timeout 65;
include vhost/*.conf;
server {
  listen 80;
  server_name localhost;
... <br>// mkdir -p /usr/local/nginx/conf/vhost
// vim /usr/local/nginx/conf/vhost/www.jfedu.net.conf
server {
  server_name www.jfedu.net;
  root /usr/local/nginx/html/www;
  location / {
    index index.html;
  }
}
// vim /usr/local/nginx/conf/vhost/blog.jfedu.net.conf
server {
  server_name blog.jfedu.net;
  root /usr/local/nginx/html/blog;
  location / {
    index index.html;
  }
}
# 創建目錄: <br>// mkdir -p /usr/local/nginx/html/{www,blog}
# 創建測試頁面: <br>// echo "this is www page" > /usr/local/nginx/html/www/index.html
// echo "this is blog page" > /usr/local/nginx/html/blog/index.html
# 創建本地解析: <br>// echo "192.168.75.124 www.jfedu.net blog.jfedu.net" > /etc/hosts
重啓服務,訪問測試: <br>// cd /usr/local/nginx/sbin/nginx -s reload
// curl www.jfedu.net
this is www page
// curl blog.jfedu.net
this is blog page
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章