2017-03-21 35 views
0

以下の設定を最適化/最小化することは可能ですか?NGINX仮想ホスト設定の最小化と最適化

私はすべてのリダイレクトをより簡単なものにマージすることが可能でなければならないと感じています。

ます。http:// & http://www & https://www> https://で

私は問題を持っていたし、落ち着いてきましたけど。

変数がNGINX設定でサポートされていないことを理解していますので、たとえばログの場所を手動で定義する必要があります。すべての仮想ホストのデフォルトの場所を設定する方法はありますか?

すべての仮想ホストに同じssl-params.confファイルを使用します。 vhost単位でこれをデフォルトにして無効にすることはできますか?

# Redirect http:// & http://www to https:// 
server { 
    server_name example.com www.example.com; 
    return 301 https://example.com$request_uri; 
} 

# Redirect https://www to https:// 
server { 
    listen 443 ssl; 
    server_name www.example.com; 
    return 301 https://example.com/$request_uri; 
} 

# Main config 
server { 
    listen 443 ssl; 
    server_name example.com; 

    # SSL config 
    include snippets/ssl-example.com.conf; 
    include snippets/ssl-params.conf; 

    # Error logs 
    access_log /srv/logs/nginx.access.example.com.log; 
    error_log srv/logs/nginx.error.example.com.log; 

    # Root dir 
    location/{ 
    root /srv/example.com/_site/; 
    index index.php index.html index.htm; 
    try_files $uri $uri/ /index.php?$args; 
    } 

    # Caching 
    location ~ .php$ { 
    root /srv/example.com/_site/; 
    include snippets/fastcgi-php.conf; 
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { 
    root /srv/example.com/_site/; 
    expires 365d; 
    } 
    location ~* \.(pdf)$ { 
    root /srv/example.com/_site/; 
    expires 30d; 
    } 

    # SSL 
    location /.well-known { 
    allow all; 
    } 
} 

答えて

0

私は変数はnginxの設定ファイルでサポートされていない理解して、私は手動で例えばログの場所を定義する必要があります。すべての仮想ホストのデフォルトの場所を設定する方法はありますか?

はい、ディストリビューションのデフォルト(例:/var/log/nginx/access.log)を使用して、設定またはスティックのhttpコンテキストで定義してください。

すべての仮想ホストに対して同じssl-params.confファイルを使用します。 vhost単位でこれをデフォルトにして無効にすることはできますか?

それはあなたがincludeディレクティブを通してそれを必要な場所あなたの周りの他の方法は、それを有効に動作します。ここで


は短く設定(未テスト)である:

http { 
    error_log /srv/logs/nginx.error.example.com.log; 
    access_log /srv/logs/nginx.access.example.com.log; 
    index  index.php index.html index.htm; 

    server { 
     listen 80; 
     listen 443 ssl; 
     server_name .example.com; 

     include snippets/ssl-example.com.conf; 
     include snippets/ssl-params.conf; 

     return 301 https://example.com$request_uri; 
    } 

    server { 
     listen 443 ssl; 
     server_name example.com; 
     root /srv/example.com/_site/; 

     include snippets/ssl-example.com.conf; 
     include snippets/ssl-params.conf; 

     location/{ 
      location ~ \.php$ { 
       include snippets/fastcgi-php.conf; 
       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

       try_files $uri =404; 
      } 

      location ~* \.(jpe?g|png|gif|ico|css|js)$ { 
       expires 365d; 
      } 

      location ~* \.(pdf)$ { 
       expires 30d; 
      } 

      try_files $uri $uri/ /index.php?$args; 
     } 

     location /.well-known { 
      allow all; 
     } 
    } 
} 
関連する問題