diff --git a/docs/3.x.x/en/configurations/configurations.md b/docs/3.x.x/en/configurations/configurations.md index 176b6e0457..9c908f9cd3 100644 --- a/docs/3.x.x/en/configurations/configurations.md +++ b/docs/3.x.x/en/configurations/configurations.md @@ -332,6 +332,11 @@ Most of the application's configurations are defined by environment. It means th - `port` (integer): Port on which the server should be running. Default value: `1337`. - `autoReload` - `enabled` (boolean): Enable or disabled server reload on files update. Default value: depends on the environment. + - `proxy` + - `enabled` (boolean): Enable proxy support such as Apache or Nginx. Default value: `false`. + - `ssl` (boolean): Enable proxy SSL support + - `host` (string): Host name your proxy service uses for Strapi. + - `port` (integer): Port that your proxy service accepts connections on. - [`cron`](https://en.wikipedia.org/wiki/Cron) - `enabled` (boolean): Enable or disable CRON tasks to schedule jobs at specific dates. Default value: `false`. - `admin` @@ -343,6 +348,33 @@ Most of the application's configurations are defined by environment. It means th - `source` (string): Define the source mode (origin, host, custom). - `folder` (string): Indicate what the plugins folder in `host` source mode. +#### Example + +**Path —** `./config/environments/**/server.json`. + +As an example using this configuration with Nginx your server would respond to `https://example.com:8443` instead of `http://localhost:1337` + +**Note:** you will need to configure Nginx or Apache as a proxy before configuring this example. + +```json +{ + "host": "localhost", + "port": 1337, + "proxy": { + "enabled": true, + "ssl": true, + "host": "example.com", + "port": 8443 + }, + "autoReload": { + "enabled": true + }, + "cron": { + "enabled": true + } +} +``` + *** ## Dynamic configurations diff --git a/packages/strapi-generate-new/files/config/environments/development/server.json b/packages/strapi-generate-new/files/config/environments/development/server.json index 2c9235833f..46db2086bb 100755 --- a/packages/strapi-generate-new/files/config/environments/development/server.json +++ b/packages/strapi-generate-new/files/config/environments/development/server.json @@ -1,6 +1,9 @@ { "host": "localhost", "port": 1337, + "proxy": { + "enabled": false + }, "autoReload": { "enabled": true }, diff --git a/packages/strapi-generate-new/files/config/environments/production/server.json b/packages/strapi-generate-new/files/config/environments/production/server.json index 0a35d003aa..bc0294e31f 100755 --- a/packages/strapi-generate-new/files/config/environments/production/server.json +++ b/packages/strapi-generate-new/files/config/environments/production/server.json @@ -1,6 +1,9 @@ { "host": "localhost", "port": "${process.env.PORT || 1337}", + "proxy": { + "enabled": false + }, "autoReload": { "enabled": false }, diff --git a/packages/strapi-generate-new/files/config/environments/staging/server.json b/packages/strapi-generate-new/files/config/environments/staging/server.json index 0a35d003aa..bc0294e31f 100755 --- a/packages/strapi-generate-new/files/config/environments/staging/server.json +++ b/packages/strapi-generate-new/files/config/environments/staging/server.json @@ -1,6 +1,9 @@ { "host": "localhost", "port": "${process.env.PORT || 1337}", + "proxy": { + "enabled": false + }, "autoReload": { "enabled": false }, diff --git a/packages/strapi-plugin-settings-manager/admin/src/translations/en.json b/packages/strapi-plugin-settings-manager/admin/src/translations/en.json index 2f613a630e..b9365fada3 100755 --- a/packages/strapi-plugin-settings-manager/admin/src/translations/en.json +++ b/packages/strapi-plugin-settings-manager/admin/src/translations/en.json @@ -107,6 +107,12 @@ "form.server.item.port": "Port", "form.server.item.cron": "Cron", + "form.server.item.proxy": "Proxy Settings", + "form.server.item.proxy.enable": "Proxy Enable", + "form.server.item.proxy.ssl": "Proxy SSL", + "form.server.item.proxy.host": "Proxy Host", + "form.server.item.proxy.port": "Proxy Port", + "form.language.name": "Languages", "form.language.description": "Configure your languages.", "form.language.choose": "Choose a language:", diff --git a/packages/strapi-plugin-settings-manager/services/SettingsManager.js b/packages/strapi-plugin-settings-manager/services/SettingsManager.js index 3945a3eeda..8821a267d3 100755 --- a/packages/strapi-plugin-settings-manager/services/SettingsManager.js +++ b/packages/strapi-plugin-settings-manager/services/SettingsManager.js @@ -452,6 +452,41 @@ module.exports = { value: _.get(strapi.config, `environments.${env}.server.cron.enabled`, null) } ] + }, + { + name: 'form.server.item.proxy', + items: [ + { + name: 'form.server.item.proxy.enable', + target: 'server.proxy.enabled', + type: 'boolean', + value: _.get(strapi.config, `environments.${env}.server.proxy.enabled`, null), + items: [ + { + name: 'form.server.item.proxy.host', + target: 'server.proxy.host', + type: 'string', + value: _.get(strapi.config, `environments.${env}.server.proxy.host`, null), + validations: {} + }, + { + name: 'form.server.item.proxy.port', + target: 'server.proxy.port', + type: 'number', + value: _.get(strapi.config, `environments.${env}.server.proxy.port`, null), + validations: {} + }, + { + name: 'form.server.item.proxy.ssl', + target: 'server.proxy.ssl', + type: 'boolean', + value: _.get(strapi.config, `environments.${env}.server.proxy.ssl`, null), + validations: {} + } + ], + validations: {} + } + ] } ] }), diff --git a/packages/strapi/lib/core/configurations.js b/packages/strapi/lib/core/configurations.js index 8fa9da809b..d39e61fec4 100755 --- a/packages/strapi/lib/core/configurations.js +++ b/packages/strapi/lib/core/configurations.js @@ -318,9 +318,25 @@ module.exports.app = async function() { return acc; }, {}); + // default settings this.config.port = get(this.config.currentEnvironment, 'server.port') || this.config.port; this.config.host = get(this.config.currentEnvironment, 'server.host') || this.config.host; - this.config.url = `http://${this.config.host}:${this.config.port}`; + + // default construct url + this.config.url = `http://${this.config.host}:${this.config.port}` + + // proxy settings + this.config.proxy = get(this.config.currentEnvironment, 'server.proxy' || {}); + + // check if SSL enabled and construct proxy url + function getProxyUrl(ssl, url) { + return `http${ssl ? 's' : ''}://${url}`; + } + + // check if proxy is enabled and construct url + if (get(this.config, 'proxy.enabled')) { + this.config.url = getProxyUrl(this.config.proxy.ssl, `${this.config.proxy.host}:${this.config.proxy.port}`); + } }; const enableHookNestedDependencies = function (name, flattenHooksConfig, force = false) {