nginx配置虚拟主机
admin
2023-03-18 12:43:27
0

1.基于端口的虚拟主机

server {
        listen       80;
        server_name  www.nginx1.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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

server{
        listen 9527;
        server_name www.nginx1.com;

        location / {
            root /opt/html;
            index index.html index.htm index.php;
        }
}


2.基于端口的虚拟主机

server {
        listen       80;
        server_name  www.nginx1.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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

server{
        listen 9527;
        server_name www.nginx2.com;

        location / {
            root /opt/html;
            index index.html index.htm index.php;
        }
}


3.基于端口的虚拟主机

#执行命令虚拟IP
ifconfig eth0:1 192.168.2.141 netmask 255.255.255.0


#修改nginx.conf配置文件
server {
        listen       192.168.2.140:80;
        server_name  192.168.2.140;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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

server{
        listen 192.168.2.141:9527;
        server_name 192.168.2.141;

        location / {
            root /opt/html;
            index index.html index.htm index.php;
        }
}

nginx配置虚拟主机

上一篇:NFS详解

下一篇:memcached 快速入门

相关内容

热门资讯

炒股精神病院去年被罚117万,... 精神病院作为投资主体,而且在云谲波诡的股市里打拼得很好,本身就是一个让人好奇的事情。现在既然投资行为...
这个法国人,真让人刮目相看 政坛老将,第四次冲击总统宝座。更让人刮目相看的,是他对华的清醒表态他就是梅朗雄,法国左翼政党的领导人...
台“军购条例”大幅缩水,美国果... 【文/观察者网 王恺雯】台立法机构5月8日表决通过蓝白版“军购特别条例”,预算上限由赖清德当局要求的...
奋斗华章丨平凡亦有光 奋斗即力... 奋斗华章丨平凡亦有光 奋斗即力量 五月的风,裹挟着劳动的滚烫与青春的赤诚,吹遍华夏大地。 当五一劳...
中国移动发布Token运营生态... 5月8日,中国移动在2026移动云大会期间举办“词元聚力 智享未来”Token运营发展论坛,联合腾讯...
台当局滥发文化补助,涉事歌词低... 叶元之海峡导报综合报道 台民意机构“教育及文化委员会”7日邀台当局文化主管部门进行业务报告并备询,国...
国乒男女团今天冲冠,一起迎战日... 北京时间5月10日(星期日),2026伦敦世乒赛团体赛决赛将迎来巅峰对决,男团、女团决赛将分别进行,...
瑞幸,杀到农夫山泉家门口 便利店的饮料货架上,出现了瑞幸这个熟悉又陌生的名字。近日,瑞幸正式推出全新瓶装即饮咖啡,一口气上架生...
浙江多地结婚登记预约爆满 “520”马上要来了,这一天因谐音“我爱你”成为许多新人眼中登记结婚的“良辰吉日”,目前,多地“52...