質問編集履歴

2

nginxファイルの追加

2019/02/19 08:05

投稿

TakumaN
TakumaN

スコア120

test CHANGED
File without changes
test CHANGED
@@ -53,3 +53,113 @@
53
53
  なので、httpsの場合でもセッション情報を保持できるようにする方法を教えて頂けると助かります!
54
54
 
55
55
  よろしくお願いします!
56
+
57
+
58
+
59
+ ```nginx
60
+
61
+ # log directory
62
+
63
+ error_log /var/www/rails/hoge/log/nginx.error.log;
64
+
65
+ access_log /var/www/rails/hoge/log/nginx.access.log;
66
+
67
+ # max body size
68
+
69
+ client_max_body_size 2G;
70
+
71
+ upstream app_server {
72
+
73
+ # for UNIX domain socket setups
74
+
75
+ server unix:/var/www/rails/hoge/tmp/sockets/.unicorn.sock fail_timeout=0;
76
+
77
+ }
78
+
79
+
80
+
81
+
82
+
83
+ server {
84
+
85
+ listen 80;
86
+
87
+ listen [::]:80;
88
+
89
+ server_name www.hoge.com;
90
+
91
+
92
+
93
+ location / {
94
+
95
+ # httpでのアクセスをhttpsへのアクセスにリダイレクト
96
+
97
+ return 301 https://$host$request_uri;
98
+
99
+ }
100
+
101
+
102
+
103
+ }
104
+
105
+
106
+
107
+ server {
108
+
109
+ listen 443 ssl;
110
+
111
+ ssl on;
112
+
113
+ ssl_certificate /etc/letsencrypt/live/www.hoge.com/fullchain.pem;
114
+
115
+ ssl_certificate_key /etc/letsencrypt/live/www.hoge.com/privkey.pem;
116
+
117
+
118
+
119
+ #listen 80;
120
+
121
+ server_name www.hoge.com;
122
+
123
+ # nginx so increasing this is generally safe...
124
+
125
+ keepalive_timeout 5;
126
+
127
+ # 静的ファイルへのパス、ドキュメントルート
128
+
129
+ root /var/www/rails/hoge/public;
130
+
131
+ # ページ読み込みのキャッシュ
132
+
133
+ try_files $uri/index.html $uri.html $uri @app;
134
+
135
+ location @app {
136
+
137
+ # HTTPヘッダー情報
138
+
139
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
140
+
141
+ proxy_set_header Host $http_host;
142
+
143
+ proxy_redirect off;
144
+
145
+ proxy_pass http://app_server;
146
+
147
+ }
148
+
149
+
150
+
151
+ # Railsのエラーページ
152
+
153
+ error_page 500 502 503 504 /500.html;
154
+
155
+ location = /500.html {
156
+
157
+ root /var/www/rails/hoge/public;
158
+
159
+ }
160
+
161
+ }
162
+
163
+
164
+
165
+ ```

1

追記

2019/02/19 08:04

投稿

TakumaN
TakumaN

スコア120

test CHANGED
@@ -1 +1 @@
1
- railsの本番環境でセッションが消えてしまいログインできません
1
+ rails httpsアクスするとセッションが消えてしまいログインできません
test CHANGED
@@ -41,3 +41,15 @@
41
41
  end
42
42
 
43
43
  ```
44
+
45
+
46
+
47
+
48
+
49
+ 追記:
50
+
51
+ nginxの設定を変更して、http://www.hoge.comにするとログインできたので、原因はやはりhttpsにすることによって起こっていると考えられます!
52
+
53
+ なので、httpsの場合でもセッション情報を保持できるようにする方法を教えて頂けると助かります!
54
+
55
+ よろしくお願いします!