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 快速入门

相关内容

热门资讯

携程罚单的真正影响,不是酒店变... 文 | 听风译码 7月25日,市场监管总局对携程开出51.79亿元天价罚单。 全网叫好。 但如果你...
自己管理自己,我国成功发射两颗... 7月24日消息,力箭一号遥十五运载火箭今日在东风商业航天创新试验区成功发射,以“一箭5星”方式将5颗...
视频丨2026暑期档电影票房破... 据网络平台数据截至目前2026年暑期档电影总票房(含预售)突破55亿元2026年度电影总票房(含预售...
南部战区海军组织力量紧急救援越... 7月25日19时许,南部战区海军接南海救115船通报,1艘越南籍船舶在永暑礁以北38海里附近海域遇险...
演出前女主演在剧院门口遇交通事... 极目新闻记者 张皓7月26日,有多位网友发文称,《生命之旅》演员郝若琦演出前在北京保利剧院门口因交通...
央视财经曝光:打着农产品幌子,... 我国《医疗用毒性药品管理办法》明确规定,生附子属于含有毒性的中药材,国家对其有着严格的制作和使用规范...
美媒:鲁比奥,有了上位的可能性 2028年美国共和党接班战局悄然生变!曾稳居特朗普接班人首选的万斯,因伊朗战事陷入双面困境,主战派不...
一城瓷器半城窑 明代青花云龙纹缸景德镇中国陶瓷博物馆藏清代粉彩黄地梅雀纹碗景德镇中国陶瓷博物馆藏近代青花玲珑瓷矾红花...
ICC逮捕令致内塔尼亚胡出行受... 【环球网报道】据以色列《新消息报》网站26日报道,由于国际刑事法院(ICC)2024年就以色列在巴勒...
“罗永浩怒斥电视机厂商”戳中了... 7月25日晚,罗永浩发文怒斥当下电视机的产品设计。据都市快报报道,罗永浩表示,他为家中老人换了两次电...