使用Nginx来配置虚拟主机

在使用Nginx时使用VirtualHost的方法。

以下是关于接受 ekzemplaro.org 和 corona.ekzemplaro.org 的设置示例。
两者都使用 Let’s Encrypt,并将 http 重定向到 https。

#
worker_processes  1;

error_log  /var/log/nginx/error.log;

events {
    worker_connections  1024;
}


http {
    include      mime.types;
    default_type  application/octet-stream;

    sendfile  on;

    keepalive_timeout  65;
    types_hash_max_size 4096;
    server_names_hash_bucket_size 128;

    server {
        listen       80;
        server_name   ekzemplaro.org;
        access_log  /var/log/nginx/access.log;

        return 301 https://$host$request_uri;
        }

    server {
        listen  443 ssl;
        server_name   ekzemplaro.org;

        location / {
            root    /var/www/html;
            index  index.html index.htm;
        }



ssl_certificate     /etc/letsencrypt/live/ekzemplaro.org/fullchain.pem;
ssl_certificate_key   /etc/letsencrypt/live/ekzemplaro.org/privkey.pem;

     }

server {
    listen  80;
    server_name corona.ekzemplaro.org;
    access_log  /var/log/nginx/corona.access.log;

    return 301 https://$host$request_uri;

    }

server {
    listen  443 ssl;
    server_name   corona.ekzemplaro.org;

    access_log  /var/log/nginx/corona.access.log;

    root /var/www/html/corona;

ssl_certificate     /etc/letsencrypt/live/corona.ekzemplaro.org/fullchain.pem;
ssl_certificate_key   /etc/letsencrypt/live/corona.ekzemplaro.org/privkey.pem;

    }


}

确认配置文件

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

重新启动服务器

sudo systemctl restart nginx

在 Apache2 中使用 VirtualHost

广告
将在 10 秒后关闭
bannerAds