nginx同一域名同一端口下配置多主機(多項目)

在很多情況下,只有一個域名一個端口,要求使用多個站點

一、定義項目名及網站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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章