nginx同一域名同一端口下配置多主机(多项目)

    技术2022-07-10  130

    在很多情况下,只有一个域名一个端口,要求使用多个站点

    一、定义项目名及网站test1、test2

    [root@localhost ~]# mkdir -p /data/nginx/html/test1 [root@localhost ~]# mkdir -p /data/nginx/html/test2 [root@localhost ~]# echo "this is test1" >/data/nginx/html/test1/index.html [root@localhost ~]# echo "this is test2" >/data/nginx/html/test2/index.html

    二、配置nginx.conf

    http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /test1 { alias /data/nginx/html/test1; index index.html; } location /test2 { alias /data/nginx/html/test2; index index.html; }

    三、效果

    -----------------------end

    Processed: 0.014, SQL: 10