一、安裝nginx https://yq.aliyun.com/articles/101144?spm=5176.10695662.1996646101.searchclickresult.70af967bColksb 二、nginx.conf文件配置 /usr/local/nginx/conf/c ...
一、安裝nginx
https://yq.aliyun.com/articles/101144?spm=5176.10695662.1996646101.searchclickresult.70af967bColksb
二、nginx.conf文件配置
1 user root; 2 worker_processes 1; 3 4 #error_log logs/error.log; 5 #error_log logs/error.log notice; 6 #error_log logs/error.log info; 7 8 #pid logs/nginx.pid; 9 10 11 events { 12 worker_connections 1024; 13 } 14 15 error_log /usr/local/nginx/logs/error.log debug; 16 17 http { 18 include mime.types; 19 default_type application/octet-stream; 20 21 underscores_in_headers on; 22 log_format log_req_resp '$remote_addr - $remote_user [$time_local] ' 23 '"$request" $status $body_bytes_sent ' 24 '"$http_referer" "$http_user_agent" $request_time' 25 'req_header:"$request_body" req_body:"$request_body"'; 26 27 28 #access_log logs/access.log main; 29 30 sendfile on; 31 #tcp_nopush on; 32 33 34 keepalive_timeout 65; 35 36 #gzip on; 37 38 include /usr/local/nginx/conf/conf.d/*.conf; 39 40 }
/usr/local/nginx/conf/conf.d/shout.conf配置
1 upstream toshou.top{ 2 server blog.toshout.top; 3 } 4 server { 5 listen 80; 6 server_name toshou.top; 7 8 #charset koi8-r; 9 #access_log /var/log/nginx/log/host.access.log main; 10 location / { 11 proxy_pass http://toshou.top; 12 proxy_http_version 1.1; 13 proxy_set_header Host $host; 14 proxy_set_header X-Real-IP $remote_addr; 15 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16 proxy_set_header Via "nginx"; 17 } 18 19 # redirect server error pages to the static page /50x.html 20 # 21 error_page 500 502 503 504 /50x.html; 22 location = /50x.html { 23 root /usr/share/nginx/html; 24 } 25 }
綁定功能變數名稱
shou.top功能變數名稱綁定到nginx服務ip,訪問toshou.top會把請求轉發到blog.toshout.top
依此配置,使不同功能變數名稱綁定nginx伺服器ip,並創建子配置文件即可。
https配置
由於本人使用的是阿裡雲伺服器,CA證書也是在阿裡雲購買的免費證書。
1、下載證書
2、上傳證書至/usr/local/nginx/cert目錄
3、新建配置文件toshout.top_ssl.conf
1 server { 2 listen 443; 3 server_name toshout.top; 4 ssl on; 5 6 ssl_certificate /usr/local/nginx/cert/weixin.daq.pem; 7 ssl_certificate_key /usr/local/nginx/cert/weixin.daq.key; 8 9 location / { 10 proxy_pass http://blog.toshout.top; 11 proxy_http_version 1.1; 12 proxy_set_header Host $host; 13 proxy_set_header X-Real-IP $remote_addr; 14 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 15 proxy_set_header Via "nginx"; 16 } 17 }