一、背景简介

在搭建个人博客或站点时,为方便用户记住访问站点,我们大多站点管理者会使用域名进行网站的访问。

二、域名Nginx配置

2.1 global.conf

server {
    listen 443 ssl;
    server_name mpoom.cn;
    #ssl on;
    ssl_certificate  cert/mpoom.cn.pem;
    ssl_certificate_key cert/mpoom.cn.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    client_max_body_size 100M;

    location / {
        proxy_pass  http://127.0.0.1:8060;
    }
}

server {
    listen       80;
    server_name  mpoom.cn www.mpoom.cn;
    return 301 https://www.mpoom.cn$request_uri;
}

server {
    listen 443 ssl;
    server_name blog.mpoom.cn;
    ssl_certificate  cert/blog.mpoom.cn.pem;
    ssl_certificate_key cert/blog.mpoom.cn.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    client_max_body_size 100M;

    location / {
        proxy_pass  http://127.0.0.1:8060;
    }
}
server {
    listen       80;
    server_name  blog.mpoom.cn;
    location / {
        proxy_pass  http://127.0.0.1:8060;
    }
}

server {
    listen       80;
    server_name  p.mpoom.cn;
    client_max_body_size 100M;
    location / {
        proxy_pass  http://127.0.0.1:8090;
    }
}

2.2 blog_mpoom.conf

server {
    listen       8060;
    server_name  127.0.0.1 localhost;

    set $root_path "/home/github/hexo-blog/public";

    #charset koi8-r;
    #access_log  /home/running/mpoom/nginx-logs/blog/host.access.log;
    #error_log  /home/running/mpoom/nginx-logs/blog/error.log;

    location / {
        root   $root_path;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}