私は常に自分の vps に apache を使用してきました。最近、nginx に切り替えることにしました。これまで使用したことがないため、サブドメインを使用して仮想ホストを構成する際の問題をいくつか把握しています。
私のvpsはubuntu 12.04を実行しており、Apacheがインストールされていないフレッシュインストールです。
/usr/share/nginx フォルダー内に複数の Web サイトを保存したいと考えています。このディレクトリ内には、次の構造があります。
root@mauro-vps:/usr/share/nginx# tree
.
├── blog.marano.tk
│ └── public_html
│ └── index.php
└── marano.tk
└── public_html
└── index.php
ご覧のとおり、vps の IP を指す無料のドメイン名 (marano.tk) を設定しました。そして、このサーバーに2つのWebサイトを保存したい:
- blog.marano.tk
- marano.tk
nginxの仕組みを理解するためだけに。
私/etc/nginx/nginx.conf
はデフォルトのもので、その中は何も編集していません。
内部/etc/nginx/sites-aviable
には 2 つの構成ファイル (ドメインごとに 1 つ) があります。
- デフォルト (marano.tk を指す)
- blog.marano.tk
最初のファイル #/etc/nginx/sites-aviable/default
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
#root /usr/share/nginx/www;
root /usr/share/nginx/marano.tk/public_html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name marano.tk www.marano.tk;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~ \.php$ {
try_files $uri =404;
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;
}
}
2 番目のファイル/etc/nginx/sites-aviable/blog.marano.tk
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/blog.marano.tk/public_html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name blog.marano.tk www.blog.marano.tk;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~ \.php$ {
try_files $uri =404;
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;
}
}
次に、両方のファイルをシンボリック リンクしました。
ln -s /etc/nginx/sites-aviable/default /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-aviable/blog.marano.tk /etc/nginx/sites-enabled/
nginx と php を再起動した後、blog.marano.tkを指定すると、/usr/share/nginx/ blog.marano.tk の代わりに/usr/share/nginx/marano.tk/public_html/index.php内のコンテンツを取得できます。 /public_html/index.php
どこが間違っているのですか?
私の悪い英語でごめんなさい