Skip to content

Commit 86278d1

Browse files
committed
Make CertFile and KeyFile relative to CustomPath
The current code will absolute CertFile and KeyFile against the current working directory. This is quite unexpected for users. This code makes relative paths absolute against the CustomPath. Fix #4196
1 parent 1803b38 commit 86278d1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

custom/conf/app.ini.sample

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ DISABLE_ROUTER_LOG = false
282282
; not forget to export the private key):
283283
; $ openssl pkcs12 -in cert.pfx -out cert.pem -nokeys
284284
; $ openssl pkcs12 -in cert.pfx -out key.pem -nocerts -nodes
285-
CERT_FILE = custom/https/cert.pem
286-
KEY_FILE = custom/https/key.pem
285+
; Relative paths will be made absolute against the CUSTOM_PATH
286+
CERT_FILE = https/cert.pem
287+
KEY_FILE = https/key.pem
287288
; Root directory containing templates and static files.
288289
; default is the path where Gitea is executed
289290
STATIC_ROOT_PATH =

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
181181
- `SSH_LISTEN_PORT`: **%(SSH\_PORT)s**: Port for the built-in SSH server.
182182
- `OFFLINE_MODE`: **false**: Disables use of CDN for static files and Gravatar for profile pictures.
183183
- `DISABLE_ROUTER_LOG`: **false**: Mute printing of the router log.
184-
- `CERT_FILE`: **custom/https/cert.pem**: Cert file path used for HTTPS.
185-
- `KEY_FILE`: **custom/https/key.pem**: Key file path used for HTTPS.
184+
- `CERT_FILE`: **https/cert.pem**: Cert file path used for HTTPS. From 1.12 relative paths will be made absolute against `CUSTOM_PATH`.
185+
- `KEY_FILE`: **https/key.pem**: Key file path used for HTTPS. From 1.12 relative paths will be made absolute against `CUSTOM_PATH`.
186186
- `STATIC_ROOT_PATH`: **./**: Upper level of template and static files path.
187187
- `STATIC_CACHE_TIME`: **6h**: Web browser cache time for static resources on `custom/`, `public/` and all uploaded avatars.
188188
- `ENABLE_GZIP`: **false**: Enables application-level GZIP support.

modules/setting/setting.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,12 @@ func NewContext() {
554554
Protocol = HTTPS
555555
CertFile = sec.Key("CERT_FILE").String()
556556
KeyFile = sec.Key("KEY_FILE").String()
557+
if !filepath.IsAbs(CertFile) && len(CertFile) > 0 {
558+
CertFile = filepath.Join(CustomPath, CertFile)
559+
}
560+
if !filepath.IsAbs(KeyFile) && len(KeyFile) > 0 {
561+
KeyFile = filepath.Join(CustomPath, KeyFile)
562+
}
557563
case "fcgi":
558564
Protocol = FCGI
559565
case "fcgi+unix":

0 commit comments

Comments
 (0)