mirror of
https://github.com/digitalocean/nginxconfig.io.git
synced 2025-11-05 18:56:09 +08:00
Set the PHP server config per site (#232)
* Set up the php server per site. * Backwards compatibility logic for old config URLs. * Remove php global config tab. * Fix util import in website.conf.js * Fix eslint fails. * Move global php i18n keys to domain * Remove unnecessary domains verification and set fastcgi_pass in unified mode. * Convert return statement to logic operator in php_ustream.js * Move php upstream to outside the server blocks * Remove unnecessary watcher from php domain section * Fix upstream config context and conditional append * Separate backwards compatibility logic. * Remove unused i18n key from php domain and update copyright of these files * Replace all dots for underscore in php_upstream helper * Fix missing space and remove upstream comment from php config. * Fix selects $refs and watch the enable status for phpServer and phpBackupServer. * Change copyright year for all modified files. * Backwards compatibility logic for old config URLs after angularBackwardsCompatibility * Deep merge old php global config from data url, and add safe disable for phpConfigs * Move deep merge function to new helper * Fix missing disable wordpressRules and convert function declaration to arrows in deep merge helper * Fix missing css class in php domain-section
This commit is contained in:
@@ -27,7 +27,6 @@ THE SOFTWARE.
|
||||
import sslProfiles from '../../util/ssl_profiles';
|
||||
import websiteConf from './website.conf';
|
||||
import shareQuery from '../../util/share_query';
|
||||
import phpPath from '../../util/php_path';
|
||||
|
||||
export default (domains, global) => {
|
||||
const config = {};
|
||||
@@ -51,14 +50,6 @@ export default (domains, global) => {
|
||||
// HTTP (kv so we can use the same key multiple times)
|
||||
config.http = [];
|
||||
|
||||
if (global.php.phpBackupServer.computed)
|
||||
config.http.push(['upstream php', {
|
||||
server: [
|
||||
phpPath(global),
|
||||
`${phpPath(global, true)} backup`,
|
||||
],
|
||||
}]);
|
||||
|
||||
config.http.push(['charset', 'utf-8']);
|
||||
config.http.push(['sendfile', 'on']);
|
||||
config.http.push(['tcp_nopush', 'on']);
|
||||
|
||||
@@ -24,9 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import phpPath from '../../util/php_path';
|
||||
|
||||
export default (domains, global) => {
|
||||
export default (domains) => {
|
||||
const legacyRouting = domains.some(d => d.routing.legacyPhpRouting.computed);
|
||||
const config = {};
|
||||
|
||||
@@ -43,8 +41,6 @@ export default (domains, global) => {
|
||||
config.include = 'fastcgi_params';
|
||||
|
||||
config['# fastcgi settings'] = '';
|
||||
config.fastcgi_pass = domains.some(d => d.php.php.computed) && global.php.phpBackupServer.computed !== ''
|
||||
? 'php' : phpPath(global);
|
||||
config.fastcgi_index = 'index.php';
|
||||
config.fastcgi_buffers = '8 16k';
|
||||
config.fastcgi_buffer_size = '32k';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 DigitalOcean
|
||||
Copyright 2021 DigitalOcean
|
||||
|
||||
This code is licensed under the MIT License.
|
||||
You may obtain a copy of the License at
|
||||
@@ -38,6 +38,8 @@ import drupalConf from './drupal.conf';
|
||||
import magentoConf from './magento.conf';
|
||||
import joomlaConf from './joomla.conf';
|
||||
import letsEncryptConf from './letsencrypt.conf';
|
||||
import phpPath from '../../util/php_path';
|
||||
import phpUpstream from '../../util/php_upstream';
|
||||
|
||||
const sslConfig = (domain, global) => {
|
||||
const config = [];
|
||||
@@ -176,8 +178,8 @@ export default (domain, domains, global) => {
|
||||
// Restrict Methods
|
||||
if (Object.keys(domain.restrict).find(k => domain.restrict[k].computed && k !== 'responseCode')) {
|
||||
const allowedKeys = Object.keys(domain.restrict)
|
||||
.filter(k => !domain.restrict[k].computed && k !== 'responseCode')
|
||||
.map(e => e.replace('Method', '').toUpperCase());
|
||||
.filter(k => !domain.restrict[k].computed && k !== 'responseCode')
|
||||
.map(e => e.replace('Method', '').toUpperCase());
|
||||
|
||||
serverConfig.push(['# restrict methods', '']);
|
||||
serverConfig.push([`if ($request_method !~ ^(${allowedKeys.join('|')})$)`, {
|
||||
@@ -284,15 +286,36 @@ export default (domain, domains, global) => {
|
||||
|
||||
// PHP
|
||||
if (domain.php.php.computed) {
|
||||
if (domain.php.phpBackupServer.computed) {
|
||||
config.push([`upstream ${phpUpstream(domain)}`, {
|
||||
server: [
|
||||
phpPath(domain),
|
||||
`${phpPath(domain, true)} backup`,
|
||||
],
|
||||
}]);
|
||||
}
|
||||
|
||||
serverConfig.push(['# handle .php', '']);
|
||||
|
||||
const loc = `location ~ ${domain.routing.legacyPhpRouting.computed ? '[^/]\\.php(/|$)' : '\\.php$'}`;
|
||||
|
||||
const fastcgiPass = {
|
||||
fastcgi_pass: domain.php.phpBackupServer.computed !== ''
|
||||
? phpUpstream(domain) : phpPath(domain),
|
||||
};
|
||||
|
||||
if (global.tools.modularizedStructure.computed || domain.php.wordPressRules.computed) {
|
||||
// Modularized
|
||||
serverConfig.push([loc, { include: 'nginxconfig.io/php_fastcgi.conf' }]);
|
||||
serverConfig.push([loc, {
|
||||
...fastcgiPass,
|
||||
include: 'nginxconfig.io/php_fastcgi.conf',
|
||||
}]);
|
||||
} else {
|
||||
// Unified
|
||||
serverConfig.push([loc, phpConf(domains, global)]);
|
||||
serverConfig.push([loc, {
|
||||
...fastcgiPass,
|
||||
...phpConf(domains),
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user