teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

nginxファイルの追加

2019/02/19 08:05

投稿

TakumaN
TakumaN

スコア120

title CHANGED
File without changes
body CHANGED
@@ -25,4 +25,59 @@
25
25
  追記:
26
26
  nginxの設定を変更して、http://www.hoge.comにするとログインできたので、原因はやはりhttpsにすることによって起こっていると考えられます!
27
27
  なので、httpsの場合でもセッション情報を保持できるようにする方法を教えて頂けると助かります!
28
- よろしくお願いします!
28
+ よろしくお願いします!
29
+
30
+ ```nginx
31
+ # log directory
32
+ error_log /var/www/rails/hoge/log/nginx.error.log;
33
+ access_log /var/www/rails/hoge/log/nginx.access.log;
34
+ # max body size
35
+ client_max_body_size 2G;
36
+ upstream app_server {
37
+ # for UNIX domain socket setups
38
+ server unix:/var/www/rails/hoge/tmp/sockets/.unicorn.sock fail_timeout=0;
39
+ }
40
+
41
+
42
+ server {
43
+ listen 80;
44
+ listen [::]:80;
45
+ server_name www.hoge.com;
46
+
47
+ location / {
48
+ # httpでのアクセスをhttpsへのアクセスにリダイレクト
49
+ return 301 https://$host$request_uri;
50
+ }
51
+
52
+ }
53
+
54
+ server {
55
+ listen 443 ssl;
56
+ ssl on;
57
+ ssl_certificate /etc/letsencrypt/live/www.hoge.com/fullchain.pem;
58
+ ssl_certificate_key /etc/letsencrypt/live/www.hoge.com/privkey.pem;
59
+
60
+ #listen 80;
61
+ server_name www.hoge.com;
62
+ # nginx so increasing this is generally safe...
63
+ keepalive_timeout 5;
64
+ # 静的ファイルへのパス、ドキュメントルート
65
+ root /var/www/rails/hoge/public;
66
+ # ページ読み込みのキャッシュ
67
+ try_files $uri/index.html $uri.html $uri @app;
68
+ location @app {
69
+ # HTTPヘッダー情報
70
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71
+ proxy_set_header Host $http_host;
72
+ proxy_redirect off;
73
+ proxy_pass http://app_server;
74
+ }
75
+
76
+ # Railsのエラーページ
77
+ error_page 500 502 503 504 /500.html;
78
+ location = /500.html {
79
+ root /var/www/rails/hoge/public;
80
+ }
81
+ }
82
+
83
+ ```

1

追記

2019/02/19 08:04

投稿

TakumaN
TakumaN

スコア120

title CHANGED
@@ -1,1 +1,1 @@
1
- railsの本番環境でセッションが消えてしまいログインできません
1
+ rails httpsアクスするとセッションが消えてしまいログインできません
body CHANGED
@@ -19,4 +19,10 @@
19
19
  render("users/new")
20
20
  end
21
21
  end
22
- ```
22
+ ```
23
+
24
+
25
+ 追記:
26
+ nginxの設定を変更して、http://www.hoge.comにするとログインできたので、原因はやはりhttpsにすることによって起こっていると考えられます!
27
+ なので、httpsの場合でもセッション情報を保持できるようにする方法を教えて頂けると助かります!
28
+ よろしくお願いします!