Nginxでバーチャルホストの設定をしましたが、少しハマりましたので、覚書にしました。
基本は設定ファイルの/etc/nginx/sites-available/defaulにserver {}ディレクティブを書くだけですが、defaultのデフォルトでは、最初のくだりが次のようになっています。
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; ... ... ... }
それで、基本はこのserverディレクティブを、ドキュメントルート(root)とサーバー名をバーチャルホスト分だけ変えて書き連ねるだけですが、「listen 80 default_server;」のところは、「listen 80;」とする必要がありました。ということで、サイト管理者の方では、
# You may add here your # server { # ... # } # statements for each of your virtual hosts to this file ## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki.nginx.org/Pitfalls # http://wiki.nginx.org/QuickStart # http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # file but keep this around for reference. Or just disable in sites-enabled. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## server { listen 80; # listen 80 default_server; # listen [::]:80 default_server ipv6only=on; root /var/www/wordpress1; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name www.it-ishin.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules if (!-e $request_filename) { rewrite ^(.+)$ /index.php last; } } #error_page 404 /404.html; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } server { listen 80; # listen 80 default_server; # listen [::]:80 default_server ipv6only=on; root /var/www/wordpress2; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name www2.it-ishin.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules if (!-e $request_filename) { rewrite ^(.+)$ /index.php last; } } #error_page 404 /404.html; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }
となっています。最近では、インターネット最大手の一角であるGMOのお名前.serverのVPSが、CentOS6.5を採用した場合ですが、NginxとPHP,MySQLの組み合わせを選べるようになっています。