【バックグラウンド環境を構築する】nginx http配置二級ドメイン名

4623 ワード

一、安全ルール設定ポート
自分でクラウドサービスプラットフォームを購入したコンソールの中で、クラウドサーバの中で、「安全ルール」を選択してネットルールに設定し、ポートをサブドメインのポートに設定し、通常使用しているポートを使用しないでください。
二、先にサービスを開始する
まず第二級ドメイン名サーバをオンにして、ポートはセキュリティルールが一致すればいいです。例えば、オープンした3000ポートはドメイン名を通じて直接にアクセスできます。
http://xxx.com:3000
三、コンフィギュレーション
ディレクトリ下のconfディレクトリのnginx.co nfをnginxにインストールします。開く
cd /usr/local/nginx/conf
編集を行います
vi nginx.conf
使用状況一:
現在のnginxサイトを他のサイトに置き換えると、内容は以下の通りです。
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


# .....  
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
                # ----------------    ----------
                #root   html;
                # index  index.html index.htm;
                 proxy_pass http://localhost:3000;  #    
        }
       #   
}
第二の場合
二級ドメインを作るだけです。追加された内容は以下の通りです。
#user  nobody;
worker_processes  1;

# ..     

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
                root   html;
                index  index.html index.htm;
                # proxy_pass http://localhost:3000;
        }

        # ..     
    }
    # ------------------     server    }   ,         -------
   server {
        listen 80;  #   
        server_name api.xxx.cn; #   
        location / {
                proxy_pass http://localhost:3000; #      
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection 'upgrade';
                 proxy_set_header Host $host;
                 proxy_cache_bypass $http_upgrade;
        }
   }

   # ..     

}
四、nginxを再起動する
読み込みプロファイルを再起動します。
/usr/local/nginx/sbin/nginx -s reload 
覚えているのは再起動で、起動ではありません。
/usr/local/nginx/sbin/nginx -s reload 
訪問してもいいです
ソースコード
一部の注釈が取り除かれたら、見れば分かります。serverの後に一つだけ追加すればいいです。それから、パラメータを変更します。
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        rewrite ^(.*)$  https://$host$1 permanent; #   http      https  
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    

    #        server     ,      
    server {
        listen 80;  #   
        server_name api.xxx.cn; #   
        rewrite ^(.*)$  https://$host$1 permanent; #   http      https  
        location / {
            proxy_pass http://localhost:3000; #      
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }
}
【元の住所】:https://lolku.cn/web/details/posts/38