スポンサーサイト

2023.04.20 Thursday
0

    一定期間更新がないため広告を表示しています

    category:- | by:スポンサードリンク | - | - | -

    nginxつかってリバースプロキシ設定し、1つのホスト上に複数のサイトたててドメイン指定でアクセスできる(docker使う)

    2021.09.27 Monday 22:39
    0
      nginxつかってリバースプロキシ設定し、
      これで1つのホストに複数のサイトたてて、ドメイン指定でアクセスできる(ポート番号指定とかなくてアクセスいける)
      入口として
      nginxリバースプロキシ用の dockerコンテナを1つたてる
      これをwebのアクセスの入口として、受信したアクセスを次、他の既存サイトに振り分ける
      既存サイトの設定変更は必要なし
      nginx の conf.d/default.conf に振り分け対象を追記していくだけ

      以下
      urlのsitehoge1.comと、sitehoge2.com を同じサーバ上で構築した場合

      # cat docker-compose.yml
      version: '3'
      services:
      hoge_proxy:
      image: nginx:latest
      container_name: 'hoge_proxy'
      privileged: true
      volumes:
      - ./conf.d/:/etc/nginx/conf.d
      ports:
      - "80:80" # 80でここが入口
      restart: always

      # cat conf.d/default.conf
      server {
      listen 80;
      server_name sitehoge1.com; # このurlとポート番号に でアクセスされたら 下の location proxy_pass に振り分ける

      location / {
      proxy_pass http://sitehoge1:8001; # 結局ここの内容を表示
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
      }

      server {
      listen 80;
      server_name sitehoge2.com; # このurlとポート番号に でアクセスされたら 下の location proxy_pass に振り分ける

      location / {
      proxy_pass http://sitehoge2.com:8002; # 結局ここの内容を表示
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
      }
      category:nginx | by:ittoocomments(0) | - | -

      nginxでサブディレクトリ配下のphpソースを対象にアクセスできるよう設定する

      2018.09.30 Sunday 13:59
      0
        nginxでサブディレクトリ配下のphpソースを対象にアクセスできるよう設定する
        以下、xxxxx.comのドメインを取得してそのphpソースを/var/www/html/yyyyy/zzzzz配下に格納した場合の設定
        # more /etc/nginx/conf.d/xxxxx.conf 
        
        server {
            listen       80;
            server_name  xxxxx.com;
            access_log  /var/log/nginx/xxxxx.access.log  main;
        
            location / {
                root   /var/www/html/yyyyy/zzzzz;
                index  index.php index.html index.htm ;
        
            }
        
            location ~ ¥.php$ {
                root           /var/www/html/yyyyy/zzzzz;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME    $document_root/$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
        
        category:nginx | by:ittoocomments(0)trackbacks(0) | -

        nginxで、1サーバに複数のサイトを設置する場合の設定ファイルを作成

        2018.09.23 Sunday 16:37
        0
          nginxで、1サーバに複数のサイトを設置する場合の設定ファイルを作成 各サーバごとに設定ファイルを作成して以下のようにセット。 # more /etc/nginx/conf.d/xxxxx.conf
          server {
              listen       80;
              server_name  xxxxx.com;
              access_log  /var/log/nginx/xxxxx.access.log  main;
          
              rewrite /(.*).html           /index.php?para=$1   permanent;
          
              location / {
                  root   /var/www/html/xxxxx;
                  index  index.html index.htm index.php;
              }
          
              location ~ ¥.php$ {
                  root           /var/www/html/xxxxx;
                  fastcgi_pass   127.0.0.1:9000;
                  fastcgi_index  index.php;
                  fastcgi_param  SCRIPT_FILENAME    $document_root/$fastcgi_script_name;
                  include        fastcgi_params;
              }
          }
          
          category:nginx | by:ittoocomments(0)trackbacks(0) | -

          nginxでrewriteをつかってurlリダイレクトのしたよ

          2018.09.23 Sunday 11:18
          0
            nginxでrewriteをつかってurlリダイレクトのしたよ
            
                    rewrite /area/あいうえお.html /area.php?areacd=Z001  permanent;
            	rewrite /list/areacd/(.*)/special/(.*)/(.*).html     /list.php?areacd=$1&specialcd=$2  permanent;
            
            
            category:nginx | by:ittoocomments(0)trackbacks(0) | -

            nginxをcentosにインストール FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client がでまくる

            2018.09.22 Saturday 02:01
            0
              nginxをcentosにインストール FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client がでまくる

              nginxをcentosにインストールしてphpファイル実行せずにはまる
              はまった点が2つ
              ・php-fpmをインストールしてなかった
              ・confでrootの設定


              apacheみたいにapacheいれればいいだけかと思ってたのね
              あと ファイルの置き場所してもデフォルトの
              root html;
              ではうまくいかなかった
              root /usr/share/nginx/html;
              にしたらようやく動いた


              ■php-fpmをインストール
              sudo yum -y install php-fpm
              systemctl enable php-fpm
              systemctl start php-fpm
              あと、設定ファイル編集。groupとuserをapacheではなくnginxを指定した
              vi /etc/php-fpm.d/www.conf
              service php-fpm restart

              ■nginx インストール
              repoファイル作成
              # cat nginx.repo 
              [nginx]
              name=nginx repo
              baseurl=http://nginx.org/packages/centos/7/$basearch/
              gpgcheck=0
              enabled=1
              

              cd /etc/yum.repos.d
              ls -ltr
              vi nginx.repo
              sudo yum -y --enablerepo=nginx install nginx
              


              ■/etc/nginx/conf.d/default.conf
              server {
                  listen       80;
                  server_name  localhost;
              
                  location / {
                      root   /usr/share/nginx/html;
                      index  index.html index.htm index.php;
                  }
              
                  location ~ ¥.php$ {
                      root           /usr/share/nginx/html;
                      fastcgi_pass   127.0.0.1:9000;
                      fastcgi_index  index.php;
                      fastcgi_param  SCRIPT_FILENAME    $document_root/$fastcgi_script_name;
                      include        fastcgi_params;
                  }
              

              ■エラーログ
              2018/09/22 00:28:31 [notice] 34123#34123: signal process started
              2018/09/22 00:30:11 [error] 34233#34233: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 
              server: localhost, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: 
              

              ■よく使ったコマンド
              nginx -s stop
              nginx
              category:nginx | by:ittoocomments(0)trackbacks(0) | -

              ad
              Calender
                   12
              3456789
              10111213141516
              17181920212223
              24252627282930
              31      
              << March 2024 >>
              Selected entry
              PR
              Category
              Archives
              Recommend
              Link
              Profile
              Search
              Others
              Mobile
              qrcode
              Powered
              無料ブログ作成サービス JUGEM