Maison > Opération et maintenance > Nginx > le corps du texte

Comment configurer le nom de domaine hôte Nginx

PHPz
Libérer: 2023-06-03 13:13:04
avant
1931 Les gens l'ont consulté

1. Configurez plusieurs ports pour accéder à différents fichiers

Même nom de domaine, différents ports, différents fichiers

#两个不同文件夹,分别存放不同文件
[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!
Copier après la connexion

#Modifiez le module serveur, pointez le site avec le port 80 vers un dossier, puis copiez le serveur ci-dessous et modifiez le port

[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;
    }
}
}
Copier après la connexion

#Accès au navigateur

Comment configurer le nom de domaine hôte Nginx

2. Configurez différents noms de domaine pour accéder à différents fichiers

Même port, différents noms de domaine, différents fichiers

#Quatre dossiers, correspondant à différents contenus de fichiers

[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
Copier après la connexion

#Modifiez le fichier de configuration

[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;
    }
}
#正则表达式域名
    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
Copier après la connexion

#Configurez le fichier hôte hôte et accédez aux résultats dans "C:WindowsSystem32driversetchosts"

Comment configurer le nom de domaine hôte Nginx

#

Comment configurer le nom de domaine hôte Nginx

Fin générique, telle que www.example.*

  • Expression régulière

  • Par défaut valeur

  • 3. Configurez différents noms de domaine pour accéder au même fichier

    Même port, différents noms de domaine, le même fichier
  • [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再添加一个域名,不需要在复制一个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
    Copier après la connexion
  • #Le fichier hôte de cet hôte

  • #Les résultats d'accès sont les suivants :

  • Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:yisu.com
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!