亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Nginx主機(jī)域名配置實(shí)現(xiàn)

 更新時(shí)間:2023年03月15日 14:16:21   作者:維運(yùn)  
本文主要介紹了Nginx主機(jī)域名配置實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一、配置多個(gè)端口訪問(wèn)不同文件

相同域名,不同端口,不同文件

#兩個(gè)不同文件夾,分別存放不同文件
[root@nginx ~]# mkdir /www/work_01 -p
[root@nginx ~]# mkdir /www/work_02
[root@nginx ~]# vim /www/work_01/index.html 
this is work_01!
[root@nginx ~]# vim /www/work_02/index.html
this is work_02!

#編輯其中server模塊,把端口80的站點(diǎn)指向一個(gè)文件夾,再?gòu)?fù)制這個(gè)server到下面,修改端口

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
#80端口,指向work_01的文件夾
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /www/work_01;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
#8080端口,指向work_02的文件夾
    server {
    listen 8080;
    server_name localhost;
    location / {
    root /www/work_02;
    index index.html index.htm;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}
}

#瀏覽器訪問(wèn)

二、配置不同域名訪問(wèn)不同文件

相同端口,不同域名,不同文件

#四個(gè)文件夾,分別對(duì)應(yīng)不同文件內(nèi)容

[root@nginx ~]# cd /www/
[root@nginx www]# mkdir work_03
[root@nginx www]# mkdir work_04
[root@nginx www]# echo "This is work_03" > work_03/index.html
[root@nginx www]# echo "This is work_04" > work_04/index.html
[root@nginx www]# ls
work_01  work_02  work_03  work_04

#修改配置文件

[root@nginx www]# vim /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    sendfile        on;
    keepalive_timeout  65;
#通配符在后的域名
    server {
        listen       80;
        server_name  www.haha.*;
        location / {
            root   /www/work_01;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
#精確域名
    server {
    listen 80;
    server_name www.haha.com;
    location / {
    root /www/work_02;
    index index.html index.htm;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}
#通配符在前的域名
    server {
        listen 80;
        server_name *.haha.com;
    location / {
        root /www/work_03;
        index index.html index.htm;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}
#正則表達(dá)式域名
    server {
        listen 80;
        server_name ~\w+.com;
    location / {
        root /www/work_04;
        index index.html index.htm;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}
}
[root@nginx www]# systemctl restart nginx

#配置宿主機(jī)host文件,在"C:\Windows\System32\drivers\etc\hosts"

#訪問(wèn)結(jié)果

sever_name匹配順序:

  • 精準(zhǔn)匹配
  • 通配符開(kāi)頭,比如*.example.com
  • 通配符結(jié)尾,比如www.example.*
  • 正則表達(dá)式
  • 默認(rèn)值

三、配置不同域名訪問(wèn)同個(gè)文件

相同端口,不同域名 ,同個(gè)文件

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
#只需要在server_name再添加一個(gè)域名,不需要在復(fù)制一個(gè)server_name
    server {
        listen       80;
        server_name  www.xixi.com www.qiqi.com;
        location / {
            root   /www/work_01;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
[root@nginx ~]# systemctl restart nginx

#該宿主機(jī)的host文件

#訪問(wèn)結(jié)果如下:

到此這篇關(guān)于Nginx主機(jī)域名配置實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx主機(jī)域名配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問(wèn)資源時(shí)出現(xiàn)404

    nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問(wèn)資源時(shí)出現(xiàn)404

    這篇文章主要介紹了nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問(wèn)資源時(shí)出現(xiàn)404,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • Windows下Nginx+PHP5的安裝與配置方法

    Windows下Nginx+PHP5的安裝與配置方法

    Nginx 是一個(gè)輕量級(jí)的高性能 Http WebServer,以事件驅(qū)動(dòng)方式編寫(xiě),因此相比 Apache 而言,Nginx 更加穩(wěn)定、性能更好,而且配置簡(jiǎn)單,資源占用較低。
    2010-06-06
  • nginx 讓users有權(quán)限啟動(dòng)的兩種方法

    nginx 讓users有權(quán)限啟動(dòng)的兩種方法

    這篇文章主要介紹了nginx 讓users有權(quán)限啟動(dòng)兩種方法的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Centos7 安裝Nginx整合Lua的示例代碼

    Centos7 安裝Nginx整合Lua的示例代碼

    這篇文章主要介紹了Centos7 安裝Nginx整合Lua的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • Nginx配置同時(shí)支持http和https的兩種方式

    Nginx配置同時(shí)支持http和https的兩種方式

    現(xiàn)在的網(wǎng)站支持Https幾乎是標(biāo)配功能,Nginx能很好的支持Https功能,本文主要介紹了Nginx配置同時(shí)支持http和https的兩種方式,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-03-03
  • Nginx解決Http慢攻擊(Slow HTTP Attack)的方法

    Nginx解決Http慢攻擊(Slow HTTP Attack)的方法

    緩慢的HTTP拒絕服務(wù)攻擊是一種專門(mén)針對(duì)于Web的應(yīng)用層拒絕服務(wù)攻擊,本文給大家介紹了Nginx解決Http慢攻擊(Slow HTTP Attack)的方法,需要的朋友可以參考下
    2024-02-02
  • Nginx處理跨域問(wèn)題小結(jié)

    Nginx處理跨域問(wèn)題小結(jié)

    這篇文章主要介紹了Nginx處理跨域問(wèn)題小結(jié),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-01-01
  • Nginx虛擬主機(jī)的六種配置(最全)

    Nginx虛擬主機(jī)的六種配置(最全)

    利用虛擬主機(jī),不用為每個(gè)要運(yùn)行的網(wǎng)站提供一臺(tái)單獨(dú)的Nginx服務(wù)器或單獨(dú)運(yùn)行一組Nginx進(jìn)程,本文主要介紹了Nginx虛擬主機(jī)的六種配置,具有一定的參考價(jià)值,感興趣的可以了解下
    2023-08-08
  • Nginx配置多臺(tái)機(jī)器實(shí)現(xiàn)負(fù)載均衡的教程詳解

    Nginx配置多臺(tái)機(jī)器實(shí)現(xiàn)負(fù)載均衡的教程詳解

    這篇文章主要為大家詳細(xì)介紹了Nginx配置多臺(tái)機(jī)器實(shí)現(xiàn)負(fù)載均衡的相關(guān)教程,文中的示例代碼簡(jiǎn)潔易懂,有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • Nginx啟動(dòng)常見(jiàn)錯(cuò)誤及解決方法

    Nginx啟動(dòng)常見(jiàn)錯(cuò)誤及解決方法

    重新啟動(dòng)服務(wù)器發(fā)現(xiàn)報(bào)nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)錯(cuò)誤,怎么回事如何解決呢,下面腳本之家小編給大家解答下
    2016-08-08

最新評(píng)論