1

サイトの開発インスタンスとステージング インスタンスの両方を実行するサーバーがあり、各バージョンはポート 80 と 443 で応答する必要があります。ステージング インスタンスは 1 つしかありませんが、期待どおりに動作しますが、開発インスタンスは --ユーザーごとに構成されています-どちらかのプロトコルで特定のページを直接ロードしますが、一方のポートのページにいて、もう一方のポートにリンクしようとすると失敗します。

私の設定

  server {
    listen 80;
    server_name ~^dev\.(?<username>[^.]+)\.client\.tld\.net$
                ~^(?<username>[^.]+)\.client\.dev\.tld\.net$
                ~^(?<username>[^.]+)\.dev\.client\.tld\.net$;

    location / {
      rewrite ^(.*) http://$username.client.tld.net$1 permanent;
    }
  }
  # This is the primary host that will ultimately answer requests.
  server {
    listen      80;
    server_name ~^(?<username>[^.]+)\.client\.tld\.net$;
    root        /home/$username/client/www/app/webroot;
    index       index.php;

    access_log /var/log/nginx/client.sandbox.access.log;
    error_log  /var/log/nginx/client.sandbox.error.log;

    location / {
      try_files $uri $uri/ /index.php?url=$uri;
    }

    location ~ \.php$ {
      include /etc/nginx/conf/php;
    }

    include /etc/nginx/conf/expire_content;
    include /etc/nginx/conf/ignore;
  }

  server {
  listen 443 ssl;
  server_name ~^dev\.(?<username>[^.]+)\.client\.tld\.net$
              ~^(?<username>[^.]+)\.client\.dev\.tld\.net$
              ~^(?<username>[^.]+)\.dev\.client\.tld\.net$;

  location / {
    rewrite ^(.*) https://$username.client.tld.net$1 permanent;
  }
}
# This is the primary host that will ultimately answer requests.
server {
  listen      443 ssl;
  server_name ~^(?<username>[^.]+)\.client\.tld\.net$;
  root        /home/$username/client/www/app/webroot;
  index       index.php;

  include /etc/nginx/conf/ssl;

  access_log /var/log/nginx/client.sandbox.access.log;
  error_log  /var/log/nginx/client.sandbox.error.log;

  location / {
    try_files $uri $uri/ /index.php?url=$uri;
  }

  location ~ \.php$ {
    include /etc/nginx/conf/php;
  }

  include /etc/nginx/conf/expire_content;
  include /etc/nginx/conf/ignore;
}

構成を壊した場所はありますか?

4

1 に答える 1

2

まず第一に、両方のサーバー (HTTP と HTTPS) の本体がまったく同じであるため、4 つの個別の構成を作成する必要はありません。作業中のコンテキストに応じて、またはの$schemeいずれかを含む変数を使用できます(リダイレクト用)。次に、構成に宣言が表示されず、ブラウザで問題を引き起こす可能性のある証明書も表示されません。httphttpsrootdev

それ以外の場合、構成は私には問題ないように見えます (まあ、index宣言をhttp構成に移動できるので、常に繰り返す必要はありません)。

私があなたのために作った次の(コメント付きの)設定例をチェックしてください。多分それは役立ちます。

# Put this in http context!
index           index.php;

server {
  # One server configuration to rule them all!
  listen        80;
  listen        443 ssl;

  # Seems legit.
  server_name   ~^dev\.(?<username>[^.]+)\.client\.tld\.net$
                ~^(?<username>[^.]+)\.client\.dev\.tld\.net$
                ~^(?<username>[^.]+)\.dev\.client\.tld\.net$;

  # Where am I?
  #root          /home/$username/client/www/app/webroot;

  # No wildcard certificate? No need to specify /etc/nginx as all paths
  # in the configuration are relative to the installation path.
  #include       conf/ssl;

  location / {
    # May work as well, can't test.
    #rewrite ^(.*) $scheme://$server_name$1 permanent;
    rewrite ^(.*) $scheme://$username.client.tld.net$1 permanent;
  }
}

server {
  listen        80;
  listen        443 ssl;
  server_name   ~^(?<username>[^.]+)\.client\.tld\.net$;
  root          /home/$username/client/www/app/webroot;
  include       conf/ssl;
  access_log    /var/log/nginx/client.sandbox.access.log;
  error_log     /var/log/nginx/client.sandbox.error.log;

  location / {
    try_files $uri $uri/ /index.php?url=$uri;
  }

  location ~ \.php$ {
    include     conf/php;
  }

  include       conf/expire_content;
  include       conf/ignore;
}
于 2012-12-06T21:55:34.647 に答える