Skip to content

Commit 7d25f3b

Browse files
authored
Fix envsubst issues (#1462)
## Summary Ugh. Fixes a few envsubst related issues in the Nginx plugin: 1. The `envsubst` package seemed to have a different version of envsubst than what I expected. I replaced this package with `gettext` to get the GNU version 2. `envsubst` was replacing all the nginx variables with blanks if they weren't included in the environment, which caused Drupal and PHP related examples to stop working. This update uses `gawk` to get a list of all the current environment variables and pass them as arguments to envsubst, which will make envsubst skip any unset variables. 3. Fixed Drupal and LEPP examples to use the plugin correctly ## How was it tested? Ran `runtest` for the examples, verified that the generated nginx.conf matched previous versions.
1 parent 7c0b10d commit 7d25f3b

File tree

11 files changed

+106
-23
lines changed

11 files changed

+106
-23
lines changed

examples/servers/nginx/devbox.lock

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
"lockfile_version": "1",
33
"packages": {
44
"nginx@latest": {
5-
"last_modified": "2023-08-30T00:25:28Z",
5+
"last_modified": "2023-09-04T16:24:30Z",
66
"plugin_version": "0.0.3",
7-
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#nginx",
7+
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#nginx",
88
"source": "devbox-search",
9-
"version": "1.24.0"
9+
"version": "1.24.0",
10+
"systems": {
11+
"aarch64-darwin": {
12+
"store_path": "/nix/store/prz9lx44d3hicpmsri5rm9qk44r79ng8-nginx-1.24.0"
13+
},
14+
"aarch64-linux": {
15+
"store_path": "/nix/store/b2v5yw11gmywahlyhbqajml7hjdkhsar-nginx-1.24.0"
16+
},
17+
"x86_64-darwin": {
18+
"store_path": "/nix/store/1nyjvgj3hbhck80wkwi0h18561xbp3sy-nginx-1.24.0"
19+
},
20+
"x86_64-linux": {
21+
"store_path": "/nix/store/vc66rk5b86lx1myxr18qkgzha0fjx2ks-nginx-1.24.0"
22+
}
23+
}
1024
}
1125
}
1226
}

examples/stacks/drupal/devbox.d/nginx/nginx.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
events {}
22
http{
33
server {
4-
listen 8000;
5-
listen [::]:8000;
4+
listen 8081;
5+
listen [::]:8081;
66
server_name localhost;
7-
root ../../../web;
7+
root ../../../devbox.d/web;
88

99
error_log error.log error;
1010
access_log access.log;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
events {}
2+
http{
3+
server {
4+
listen $NGINX_WEB_PORT;
5+
listen [::]:$NGINX_WEB_PORT;
6+
server_name $NGINX_WEB_SERVER_NAME;
7+
root $NGINX_WEB_ROOT;
8+
9+
error_log error.log error;
10+
access_log access.log;
11+
client_body_temp_path temp/client_body;
12+
proxy_temp_path temp/proxy;
13+
fastcgi_temp_path temp/fastcgi;
14+
uwsgi_temp_path temp/uwsgi;
15+
scgi_temp_path temp/scgi;
16+
include mime.conf;
17+
18+
index index.html;
19+
server_tokens off;
20+
21+
index index.php index.htm index.html;
22+
23+
location / {
24+
try_files $uri /index.php?$query_string; # For Drupal >= 7
25+
}
26+
27+
location @rewrite {
28+
rewrite ^ /index.php;
29+
}
30+
31+
location ~ \.php$ {
32+
include fastcgi.conf;
33+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
34+
fastcgi_pass 127.0.0.1:$PHPFPM_PORT;
35+
fastcgi_param PATH_INFO $fastcgi_path_info;
36+
fastcgi_index index.php;
37+
}
38+
39+
# Don't allow direct access to PHP files in the vendor directory.
40+
location ~ /vendor/.*\.php$ {
41+
deny all;
42+
return 404;
43+
}
44+
45+
}
46+
}

examples/stacks/drupal/devbox.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"git@latest",
44
55
"php81Packages.composer@latest",
6-
"nginx@latest",
7-
"mariadb@latest"
6+
"mariadb@latest",
7+
"nginx@latest"
88
],
99
"shell": {
1010
"init_hook": [],
@@ -20,4 +20,4 @@
2020
]
2121
}
2222
}
23-
}
23+
}

examples/stacks/drupal/devbox.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
}
4444
},
4545
"nginx@latest": {
46-
"last_modified": "2023-05-01T16:53:22Z",
46+
"last_modified": "2023-09-04T16:24:30Z",
4747
"plugin_version": "0.0.3",
48-
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#nginx",
48+
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#nginx",
49+
"source": "devbox-search",
4950
"version": "1.24.0",
5051
"systems": {
5152
"aarch64-darwin": {

examples/stacks/lepp-stack/devbox.d/nginx/nginx.conf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server {
44
listen 8089;
55
listen [::]:8089;
66
server_name localhost;
7-
root ../../../devbox.d/web;
7+
root ../../../my_app;
88

99
error_log error.log error;
1010
access_log access.log;
@@ -14,7 +14,17 @@ server {
1414
uwsgi_temp_path temp/uwsgi;
1515
scgi_temp_path temp/scgi;
1616

17-
index index.html;
18-
server_tokens off;
17+
index index.php index.htm index.html;
18+
19+
location / {
20+
try_files $uri $uri/ /index.php$is_args$args;
21+
}
22+
23+
location ~ \.php$ {
24+
include fastcgi.conf;
25+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
26+
fastcgi_pass 127.0.0.1:8082;
27+
fastcgi_index index.php;
28+
}
1929
}
2030
}

examples/stacks/lepp-stack/devbox.d/nginx/nginx.template

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ server {
1414
uwsgi_temp_path temp/uwsgi;
1515
scgi_temp_path temp/scgi;
1616

17-
index index.html;
18-
server_tokens off;
17+
index index.php index.htm index.html;
18+
19+
location / {
20+
try_files $uri $uri/ /index.php$is_args$args;
21+
}
22+
23+
location ~ \.php$ {
24+
include fastcgi.conf;
25+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
26+
fastcgi_pass 127.0.0.1:$PHPFPM_PORT;
27+
fastcgi_index index.php;
28+
}
1929
}
2030
}

examples/stacks/lepp-stack/devbox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"postgresql@14",
55
66
"php81Extensions.pgsql@latest",
7-
"nginx@1.24"
7+
"nginx@latest"
88
],
99
"env": {
1010
"NGINX_WEB_PORT": "8089",
11+
"NGINX_WEB_ROOT": "../../../my_app",
1112
"PGPORT": "5433"
1213
},
1314
"shell": {

examples/stacks/lepp-stack/devbox.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
}
2121
}
2222
},
23-
"nginx@1.24": {
24-
"last_modified": "2023-05-01T16:53:22Z",
23+
"nginx@latest": {
24+
"last_modified": "2023-09-04T16:24:30Z",
2525
"plugin_version": "0.0.3",
26-
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#nginx",
26+
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#nginx",
27+
"source": "devbox-search",
2728
"version": "1.24.0",
2829
"systems": {
2930
"aarch64-darwin": {

plugins/nginx.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "nginx",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"readme": "nginx can be configured with env variables\n\nTo customize:\n* Use $NGINX_CONFDIR to change the configuration directory\n* Use $NGINX_TMPDIR to change the tmp directory. Use $NGINX_USER to change the user\n* Use $NGINX_WEB_PORT to change the port NGINX runs on. \n Note: This plugin uses envsubst when running `devbox services` to generate the nginx.conf file from the nginx.template file. To customize the nginx.conf file, edit the nginx.template file.\n",
5-
"__packages": ["envsubst@latest"],
5+
"__packages": ["gettext@latest", "gawk@latest"],
66
"env": {
77
"NGINX_CONF": "{{ .DevboxDir }}/nginx.conf",
88
"NGINX_CONFDIR": "{{ .DevboxDir }}",

0 commit comments

Comments
 (0)