1
0

configuration-primer.mdx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ---
  2. title: "Configuration primer"
  3. description: "Fine tune your instance exactly the way you want."
  4. icon: "sliders"
  5. ---
  6. Gogs uses a layered configuration system. A default configuration is embedded in the binary, and you provide overrides in a custom file. Beyond `app.ini`, the `custom/` directory lets you override templates, static assets, locale files, and more.
  7. ## Two-layer configuration
  8. Gogs reads configuration from two sources, in order:
  9. 1. **Embedded defaults**: The [`conf/app.ini`](https://github.com/gogs/gogs/blob/main/conf/app.ini) file is compiled into the binary. You should never edit this file directly.
  10. 2. **Custom overrides**: Your `custom/conf/app.ini` file. Any value you set here takes precedence over the embedded default.
  11. This separation means binary users can upgrade without losing their settings, and source installers benefit from `custom/` being in `.gitignore`.
  12. <Tip>
  13. The embedded [`conf/app.ini`](https://github.com/gogs/gogs/blob/main/conf/app.ini) contains every available option with detailed inline comments. Use it as your canonical reference.
  14. </Tip>
  15. ### Overriding a value
  16. You only need to include the values you want to change. For example, to set a custom repository storage path and switch to production mode:
  17. ```ini
  18. RUN_MODE = prod
  19. [repository]
  20. ROOT = /home/git/gogs-repositories
  21. ```
  22. Values support INI variable interpolation with the `%(KEY)s` syntax. The embedded defaults use this extensively, for example:
  23. ```ini
  24. EXTERNAL_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
  25. ```
  26. Values also support environment variable expansion, so you can reference system environment variables directly in your configuration:
  27. ```ini
  28. [database]
  29. PASSWORD = ${DATABASE_PASSWORD}
  30. ```
  31. <Warning>
  32. If a password or value contains special characters (like backticks or `#`), wrap it in backticks, e.g., <code>PASSWORD = \`p@ss#word!\`</code>.
  33. </Warning>
  34. <Tip>
  35. Gogs uses [go-ini/ini](https://ini.unknwon.io/) as the configuration library, please refer to its documentation for the full syntax specification including multi-line values, key/value separators, and section handling.
  36. </Tip>
  37. ## The `custom/` directory
  38. The `custom/` directory is Gogs' extension point. It sits alongside the binary by default, and contains much more than just `app.ini`.
  39. ### Finding the path
  40. Run `gogs web --help` to see the custom directory path in the output. You can also override it:
  41. | Method | Example |
  42. |--------|---------|
  43. | Default | The `custom/` subdirectory next to the binary |
  44. | Environment variable | `GOGS_CUSTOM=/etc/gogs` |
  45. The work directory (parent of `custom/`) can also be overridden with `GOGS_WORK_DIR`.
  46. ### Specifying a custom config path
  47. Every Gogs subcommand accepts `-c, --config` to point to a configuration file at a non-default location:
  48. ```bash
  49. gogs web --config /etc/gogs/app.ini
  50. ```
  51. ### What lives in `custom/`
  52. ```
  53. custom/
  54. ├── conf/
  55. │ ├── app.ini # Your configuration overrides
  56. │ ├── auth.d/ # Authentication source files
  57. │ │ └── *.conf
  58. │ ├── gitignore/ # Custom .gitignore templates
  59. │ ├── license/ # Custom license templates
  60. │ ├── readme/ # Custom README templates
  61. │ ├── label/ # Custom issue label sets
  62. │ └── locale/ # Translation overrides
  63. │ └── locale_*.ini
  64. ├── templates/ # HTML template overrides
  65. ├── public/ # Static asset overrides (CSS, JS, images)
  66. └── robots.txt # Search engine crawling rules
  67. ```
  68. All of these are optional. Gogs falls back to embedded defaults when a custom file does not exist.
  69. ## Repository templates
  70. Gogs ships with embedded templates used when creating new repositories:
  71. | Template type | Embedded location |
  72. |---------------|-------------------|
  73. | `.gitignore` | `conf/gitignore/` |
  74. | License | `conf/license/` |
  75. | README | `conf/readme/` |
  76. | Issue labels | `conf/label/` |
  77. You can add your own by placing files in the corresponding `custom/conf/` subdirectory. Custom files take priority over embedded ones with the same name, so you can also override built-in templates.
  78. For example, to add a custom `.gitignore` template that appears in the repository creation form:
  79. ```
  80. custom/conf/gitignore/MyFramework
  81. ```
  82. The `[repository] PREFERRED_LICENSES` option controls which licenses appear at the top of the selection list. The names must match filenames in `conf/license/` or `custom/conf/license/`.
  83. ## Custom templates and static assets
  84. You can override any of Gogs' HTML templates or static assets by mirroring the file structure under `custom/`.
  85. **Templates** -- Place files in `custom/templates/` matching the path of the [embedded template](https://github.com/gogs/gogs/tree/main/templates) you want to override. See [Custom templates](/advancing/custom-templates) for details.
  86. **Static assets** -- Place files in `custom/public/` to override CSS, JavaScript, or images. Custom public files are served with higher priority than embedded ones.
  87. **Locale overrides** -- Place `locale_*.ini` files in `custom/conf/locale/` to override translation strings for any supported language.
  88. ## Loading assets from disk
  89. By default, Gogs serves templates, locale files, and public assets from the binary's embedded data. If you set `LOAD_ASSETS_FROM_DISK = true` in `[server]`, Gogs will load them from the work directory instead. This is mainly useful during development.