アリクラウドCentOS 7.5 Nginxを使用して複数のドメイン名と転送を構成

4578 ワード

文書ディレクトリ
  • 1.環境
  • 2.新規ディレクトリvhostはconfファイル
  • を格納する
  • 3.新しい3つのconfファイル
  • 4.静的ページhtml構成パス
  • 5.nginx構成の変更デフォルト3つのconfファイル
  • をロード
  • 6.nginx構成
  • を再ロード
    既存の3つのテストドメイン名は、同じサーバを指しています.
  • www.testa.comは、html静的ページ
  • を指す.
  • www.testb.comは、html静的ページ
  • を指す.
  • gitlab.code.com,コード管理サービス,gitlabサービスポート83
  • 1.環境
    CentOS 7.5はすでにnginxとgitlabサービスをインストールしており、そのうちnginxデフォルトポート80、gitlabポートは83に構成されており、ポート83はアリクラウドセキュリティグループに加入している!
    2.新規ディレクトリvhost保存confファイル
    [root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# mkdir /etc/nginx/vhost
    [root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# cd /etc/nginx/vhost
    

    3.新しい3つのconfファイル
    # www.testa.com
    [root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# vi vhost_testa.conf
    server {
      listen 80;
      server_name www.testa.com testa.com;
      root /home/website/testa;
    
      location / {
        index index.html index.htm index.php;
      }
    }
    
    # www.testb.com
    [root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# vi vhost_testb.conf
    server {
      listen 80;
      server_name www.testb.com testb.com;
      root /home/website/testb;
    
      location / {
        index index.html index.htm index.php;
      }
    }
    
    # gitlab.code.com
    [root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# vi vhost_gitlab.conf
    server {
      listen 80;
      server_name gitlab.code.com;
      root /usr/share/nginx/html;
      index index.html index.htm index.php; #default index
    
      location / {
        proxy_pass http://localhost:83; #       ,      
      }
    }
    

    4.静的ページhtml設定パス
    confプロファイルによると:
  • testa -->/home/website/testa
  • testb -->/home/website/testb

  • 5.nginx構成のデフォルトの3つのconfファイルのロードを変更する
    [root@iZ8vb2zp3hb2pskrfnjcrbZ vhost]# vi /etc/nginx/nginx.conf
    ...
    http {
      ...
      # Load modular configuration files from the /etc/nginx/conf.d directory.
      # See http://nginx.org/en/docs/ngx_core_module.html#include
      # for more information.
      # include /etc/nginx/conf.d/*.conf;
      #     
      include /etc/nginx/vhost/*.conf; 
      ...
    }
    

    6.nginx構成の再ロード
    [root@iZ8vb2zp3hb2pskrfnjcrbZ vhost]# nginx -s reload
    [root@iZ8vb2zp3hb2pskrfnjcrbZ vhost]# service nginx restart