Skip to content

Commit 0e82517

Browse files
committed
Make it possible to configure example nginx server
1 parent 9dfd4ee commit 0e82517

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

Diff for: examples/nginx-centos7/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN chown -R 1001:1001 /var/log/nginx
3737
RUN chown -R 1001:1001 /var/lib/nginx
3838
RUN touch /run/nginx.pid
3939
RUN chown -R 1001:1001 /run/nginx.pid
40+
RUN chown -R 1001:1001 /etc/nginx
4041

4142
USER 1001
4243

Diff for: examples/nginx-centos7/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ s2i build --incremental=true test/test-app nginx-centos7 nginx-app
8080
---> Building and installing application from source...
8181
```
8282
This will run the *save-artifacts* script which includes the custom code to backup the currently running application source, rebuild the application image, and then re-deploy the previously saved source using the *assemble* script.
83+
84+
#### Configuring nginx
85+
It is possible to configure nginx server itself via this s2i builder image. To do so, simply provide an `nginx.conf` file in the root directory of your application. The `s2i/bin/assemble` will find this configuration file and make nginx use it. See the example configuration file in [test/test-app-redirect/](test/test-app-redirect/) directory. You can build and run it by using these commands:
86+
87+
```
88+
s2i build test/test-app-redirect nginx-centos7 nginx-centos7-redirect
89+
docker run -d -p 8080:8080 nginx-centos7-redirect
90+
```
91+
92+
Going to [http://localhost:8080](http://localhost:8080) should now redirect you to [https://openshift.com](https://openshift.com).
93+
94+
More generally, it is possible to configure any kind of service using s2i, assuming that the provided `assemble` and/or `run` scripts support this and can recognize and use provided configuration files. It's also possible, assuming the s2i image supports it, to provide scripts that get executed by the s2i `run` script to further customize the functionality. Some more advanced examples of this can be found at https://github.com/sclorg/mongodb-container and https://github.com/sclorg/mariadb-container/.

Diff for: examples/nginx-centos7/s2i/bin/assemble

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ fi
2828
# bundle install, and anything else you need.
2929

3030
echo "---> Building and installing application from source..."
31-
mv /tmp/src/* /usr/share/nginx/html/
31+
if [ -f /tmp/src/nginx.conf ]; then
32+
mv /tmp/src/nginx.conf /etc/nginx/nginx.conf
33+
fi
34+
if [ "$(ls -A /tmp/src)" ]; then
35+
mv /tmp/src/* /usr/share/nginx/html/
36+
fi
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# For more information on configuration, see:
2+
# * Official English Documentation: http://nginx.org/en/docs/
3+
# * Official Russian Documentation: http://nginx.org/ru/docs/
4+
5+
worker_processes auto;
6+
error_log /var/log/nginx/error.log;
7+
pid /run/nginx.pid;
8+
9+
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
10+
include /usr/share/nginx/modules/*.conf;
11+
12+
events {
13+
worker_connections 1024;
14+
}
15+
16+
http {
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
tcp_nopush on;
25+
tcp_nodelay on;
26+
keepalive_timeout 65;
27+
types_hash_max_size 2048;
28+
29+
include /etc/nginx/mime.types;
30+
default_type application/octet-stream;
31+
32+
# Load modular configuration files from the /etc/nginx/conf.d directory.
33+
# See http://nginx.org/en/docs/ngx_core_module.html#include
34+
# for more information.
35+
include /etc/nginx/conf.d/*.conf;
36+
37+
server {
38+
listen 8080 default_server;
39+
listen [::]:8080 default_server;
40+
server_name _;
41+
root /usr/share/nginx/html;
42+
43+
# Load configuration files for the default server block.
44+
include /etc/nginx/default.d/*.conf;
45+
46+
location / {
47+
return 301 http://openshift.com;
48+
}
49+
50+
error_page 404 /404.html;
51+
location = /40x.html {
52+
}
53+
54+
error_page 500 502 503 504 /50x.html;
55+
location = /50x.html {
56+
}
57+
}
58+
}
59+

0 commit comments

Comments
 (0)