Nginx 簡介與安裝
---
Nginx是一款自由的、開源的、高性能的HTTP服務器和反向代理服務器;同時也是一個IMAP、POP3、SMTP代理服務器;Nginx可以作為一個HTTP服務器進行網站的發布處理,另外nginx可以作為反向代理進行負載均衡的實現。
Nginx主要用作與
* 反向代理
* 負載均衡
## Nginx 的安裝
#### 1.更新庫并安裝nginx
>`sudo add-apt-repository ppa:nginx/stable`
>`sudo apt-get update`
>`sudo apt-get install -y nginx`
#### 2.驗證 nginx 版本號
>`nginx -v`
>服務器返回內容 nginx version: nginx/x.x.x.x
#### 3.啟動 Nginx
>`sudo systemctl start nginx`
#### 4.查看 Nginx 狀態
>`sudo systemctl status nginx`
## Nginx 的反向代理配置
#### 1.前往Nginx配置文件夾目錄
>`cd /etc/nginx/sites-available`
#### 2.使用nano創建并配置conf
>`sudo nano www.example.com (其中www.example.com為你的域名,例www.svlog.com)`
#### 3.在創建的新文件中,輸入以下內容
>```
> server {
> listen 80;
> server_name www.example.com;
> location / {
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header X-Forwarded-Proto $scheme;
> proxy_set_header Host $http_host;
> proxy_set_header X-NginX-Proxy true;
> proxy_pass http://127.0.0.1;
> proxy_redirect off;
> proxy_http_version 1.1;
> proxy_set_header Upgrade $http_upgrade;
> proxy_set_header Connection "upgrade";
> }
>}
>```
---
至此 Nginx 安裝配置完畢
當然還有更多的比如SSL啊負載均衡啊,這里就不多做介紹了