nginxを使用した仮想ホストの作成

nginxを使用した仮想ホストの作成

nginxを使用する仮想ホスティングに問題があります。何をしても、www/example1フォルダの代わりにwww/htmlにアクセスします。誰でも問題が何であるかを理解できますか?私は何を逃したことがありませんか?

pi@homeserver:/etc/nginx/sites-enabled $ ls -l
total 4
-rw-r--r-- 1 root root 467 Sep  4 19:41 default
lrwxrwxrwx 1 root root  38 Sep  4 19:43 example1 -> /etc/nginx/sites-available/example1

デフォルトのファイルは次のとおりです。

server { 
  listen 80; 

  root /var/www/html; 
  index index.php index.html index.htm; 

  server_name localhost; 

  location / { 
     try_files $uri $uri/ =404; 
  }

    location ~\.php$ { 
        fastcgi_pass unix:/var/run/php5-fpm.sock; 
        fastcgi_split_path_info ^(.+\.php)(/.*)$; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        fastcgi_param HTTPS off; 
        try_files $uri =404;
         include fastcgi_params; 
    }
}

example1ファイルは

server { 
  listen example1.com:80; 

  root /var/www/example1.com; 
  index index.php index.html index.htm; 

  server_name example1.com www.example1.com; 

  location / { 
     try_files $uri $uri/ =404; 
  }

    location ~\.php$ { 
        fastcgi_pass unix:/var/run/php5-fpm.sock; 
        fastcgi_split_path_info ^(.+\.php)(/.*)$; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        fastcgi_param HTTPS off; 
        try_files $uri =404;
         include fastcgi_params; 
    }
}

ログにこのエラーが表示されます。

2016/09/04 21:41:08 [emerg] 1788#0: invalid host in "http://www.example1.com:80" of the "listen" directive in /etc/nginx/sites-enabled/example1.com:2

ベストアンサー1

エラーメッセージを見ると、その文をIPアドレスにnginx解析するのは難しいようです。listen example1.com:80;

listenマルチホームサーバーがあり、サービスを単一のインターフェイスに制限したい場合は、ディレクティブにIPアドレスを提供すると便利です。

ほとんどの場合、この説明listen 80;で十分です。両方のサーバーブロックに以下を使用することをお勧めします。

server {
    listen 80;
    ...
}

バラよりこのファイルもっと学ぶ。

おすすめ記事