nginx多站点配置
Posted allen167
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx多站点配置相关的知识,希望对你有一定的参考价值。
一、安装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 }
一、安装nginx
https://yq.aliyun.com/articles/101144?spm=5176.10695662.1996646101.searchclickresult.70af967bColksb
二、nginx.conf文件配置
1 |
|
/usr/local/nginx/conf/conf.d/shout.conf配置
1 |
upstream toshou.top{ |
绑定域名
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 { |
以上是关于nginx多站点配置的主要内容,如果未能解决你的问题,请参考以下文章