概要
nginxのvirtualhostの設定がうまく効きません。
以下のような二つのvirtualhost
- test.com
- example.com
を立てたいのですが、いざブラウザからアクセスするとうまくアクセスできません。
各virtualhostで設定したいことは
test.com
- http, https での通信
- http://test.com を https://test.com にリダイレクト
example.com
- http での通信
です。
test.comは問題なく動作するのですが、example.comにアクセスするとhttpsへリダイレクトがかかり、アクセスエラーとなります。
下記に設定ファイル記載します。
至らない部分のご教授お願い致します。
開発環境
- vagrant(CentOS 6.5)
- nginx 1.8.0
設定
defautl.conf
# - - - - - - - - - - - - - - - - - - # default.conf # ■ test.com # - http, https での通信 # - http://test.com を https:://test.com にリダイレクト # ■ example.com # - http での通信 # - fast cgi (socket) # - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - # test.com # - - - - - - - - - - - - - - - - - - server { listen 80; server_name .test.com; return 301 https://test.com$request_uri; } server { listen 443; server_name .test.com; ssl on; ssl_certificate /etc/nginx/conf.d/ssl/server.crt; ssl_certificate_key /etc/nginx/conf.d/ssl/server.key; if ($http_host = www.test.com) { rewrite (.*) http://test.com$1; } charset UTF-8; access_log /var/log/nginx/test.access.log main; error_log /var/log/nginx/test.error.log warn; location / { root /var/env/test/www; index index.html index.php; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd; } error_page 404 /404.html; location = /404.html { root /var/env/test/www; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/env/test/www; } try_files $uri $uri/ /index.php?q=$uri&$args; location ~ \.php$ { root /var/env/test/www; try_files $uri = 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } # - - - - - - - - - - - - - - - - - - # example.com # - - - - - - - - - - - - - - - - - - server { listen 80; server_name .example.com; if ($http_host = www.example.com) { rewrite (.*) http://example.com$1; } charset UTF-8; access_log /var/log/nginx/example.access.log main; error_log /var/log/nginx/example.error.log warn; location / { root /var/env/example/www; index index.html index.php; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd; } error_page 404 /404.html; location = /404.html { root /var/env/example/www; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/env/example/www; } try_files $uri $uri/ /index.php?q=$uri&$args; location ~ \.php$ { root /var/env/example/www; try_files $uri = 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
ローカルPCのhosts
192.168.30.10 test.com 192.168.30.10 example.com

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。