Skip to content

Commit

Permalink
add instructions for nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
vbanthia committed Nov 9, 2015
1 parent 2aabe6b commit ccaa189
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,36 @@ Start service using
fleetctl submit unit_files/stf-provider@.service
fleetctl start stf-provider@{1..3}
```

#### nginx.service
Now, its time to run our nginx server. First, update the [nginx.conf](coreos/nginx.conf) file. Run `fleetctl list-units` and check which server is running on which host and update upstream IP Address for stf_app, stf_auth, stf_storage, stf_storage_apk, stf_storage_image and stf_websocket.

To start nginx server we with use systemctl instead of fleetctl.

Firt login to one of the machine.

```sh
vagrant ssh core-01
```

Create a new file /srv/nginx/nginx.conf and paste the updated [nginx.conf](coreos/nginx.conf)
Create a new file /etc/systemd/system/nginx.service and paste [nginx.service](coreos/unit_files/nginx.service)

Start nginx using

```sh
sudo systemctl start nginx
```

Exit from ssh session

```
exit
```

Add this line in your `/etc/hosts` file
```
172.17.8.101 stf.mydomain.org
```

Now open browser and open http://stf.mydomain.org. You should be able to see STF login page.
121 changes: 121 additions & 0 deletions coreos/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
daemon off;
worker_processes 4;

events {
worker_connections 1024;
}

http {
keepalive_timeout 65;
types_hash_max_size 2048;

default_type application/octet-stream;

upstream stf_app {
server 172.17.8.[101|102|103]:3100 max_fails=0;
}

upstream stf_auth {
server 172.17.8.[101|102|103]:3200 max_fails=0;
}

upstream stf_storage_apk {
server 172.17.8.[101|102|103]:3300 max_fails=0;
}

upstream stf_storage_image {
server 172.17.8.[101|102|103]:3400 max_fails=0;
}

upstream stf_storage {
server 172.17.8.[101|102|103]:3500 max_fails=0;
}

upstream stf_websocket {
server 172.17.8.[101|102|103]:3600 max_fails=0;
}

types {
application/javascript js;
image/gif gif;
image/jpeg jpg;
text/css css;
text/html html;
}

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name stf.mydomain.org;
root /dev/null;


resolver 8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout 10s;

location ~ "^/d/1/([^/]+)/(?<port>[0-9]{5})/$" {
proxy_pass http://172.17.8.102:$port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}

location ~ "^/d/2/([^/]+)/(?<port>[0-9]{5})/$" {
proxy_pass http://172.17.8.103:$port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}

location ~ "^/d/3/([^/]+)/(?<port>[0-9]{5})/$" {
proxy_pass http://172.17.8.101:$port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}

location /s/image/ {
proxy_pass http://stf_storage_image;
}

location /s/apk/ {
proxy_pass http://stf_storage_apk;
}

location /s/ {
client_max_body_size 1024m;
client_body_buffer_size 128k;
proxy_pass http://stf_storage;
}

location /socket.io/ {
proxy_pass http://stf_websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $http_x_real_ip;
}

location /auth/ {
proxy_pass http://stf_auth/auth/;
}

location / {
proxy_pass http://stf_app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $http_x_real_ip;
}
}
}
20 changes: 20 additions & 0 deletions coreos/unit_files/nginx.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=STF nginx public load balancer
After=docker.service
Requires=docker.service
ConditionPathExists=/srv/nginx/nginx.conf

[Service]
EnvironmentFile=/etc/environment
TimeoutStartSec=0
Restart=always
ExecStartPre=/usr/bin/docker pull nginx:1.7.10
ExecStartPre=-/usr/bin/docker kill %p
ExecStartPre=-/usr/bin/docker rm %p
ExecStart=/usr/bin/docker run --rm \
--name %p \
--net host \
-v /srv/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
nginx:1.7.10 \
nginx
ExecStop=/usr/bin/docker stop -t 2 %p

0 comments on commit ccaa189

Please sign in to comment.