質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Q&A

解決済

1回答

4034閲覧

Nginx: URIの書き換えについての質問です。

marshmallowy

総合スコア204

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

0グッド

0クリップ

投稿2016/02/21 10:08

###前提・実現したいこと
NginxでURIの書き換えをしているのですが、期待通りにURIが書き換えられませんでした。

現在起きている事象は、下記の [No.1] ~ [No.4] の事象です。

[No.1] http://example.com にアクセスした時、https://www.example.com/ にリダイレクトができない 。

[No.2] https://example.com にアクセスした時、https://www.example.com/ にリダイレクトができない 。

[No.3] http://www.example.com/index.php にアクセスした時、https://www.example.com/ にリダイレクトができない 。

[No.4] http://example.com/index.php にアクセスした時、https://www.example.com/ にリダイレクトができない 。

また、定義している設定ファイルは下記の通りです。

ご教授の程、宜しくお願いいたします。

設定ファイル

server {
listen 80;
server_name www.example;
return 301 https://www.example$request_uri;
}

server {
listen 443 ssl;
server_name www.example;

ssl_certificate /usr/local/nginx/ssl/server.crt; ssl_certificate_key /usr/local/nginx/ssl/server.key; # ssl_password_file /etc/nginx/ssl/cert.password; root /var/www/html/example; access_log /var/log/nginx/example_access.log; error_log /var/log/nginx/example_error.log notice; rewrite_log on; location / { index index.html index.php; try_files $uri $uri/ @handler; expires max; } location /. { return 404; } location @handler { rewrite / /index.php; } location = / { set $first_language $http_accept_language; set $language_suffix 'english'; if ($first_language ~* 'ja') { set $language_suffix 'japanese'; } return $scheme://$host/$language_suffix/$1; } location ~ .php/ { rewrite ^(.*.php)/ $1 last; } location ~ .php$ { if (!-e $request_filename) { rewrite / /index.php last; } expires off; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /usr/local/nginx/fastcgi_params; }

}

###補足情報(言語/FW/ツール等のバージョンなど)
Vagrant Installed Version: 1.8.0

PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

PHP 5.5.9-1ubuntu4.14 (fpm-fcgi) (built: Oct 28 2015 01:38:24)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

nginx version: nginx/1.9.11
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --add-dynamic-module=/usr/build/3party_module/nginx_accept_language_module

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

server_name www.example; はおかしいですね。server_name www.example.com; ですか?
301 の後の $request_uri; も要りません。

[No. 2] については、listen 443 ssl; で、ドメインをちゃんと設定すれば、同じようにできるはずです。
まず、基本的なタイプミス等をなくして、追記して質問が良いと思います。

投稿2016/02/21 14:15

takotakot

総合スコア1111

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

marshmallowy

2016/02/22 00:50

もう一度、設定ファイルを見直してから、質問させていただきます。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問