Skip to content

Commit c289fbb

Browse files
committed
Updated README. Renamed nginx.conf to nginx.sample.conf
1 parent 5430f58 commit c289fbb

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

README.md

+52-28
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,58 @@ This is a sample app showing how to run a [3Scale](http://3Scale.com) API Proxy
88
Usage
99
---------
1010

11-
First:
12-
Get a free [3Scale](http://3Scale.com) account and a free [Heroku.com](http://Heroku.com) account if you don't already have them.
11+
#### Step 1: Get 3Scale and Heroku Accounts ####
12+
Get a free [3Scale](http://3Scale.com) account. (When prompted, I suggest letting 3Scale generate a sample application and account for you.)
13+
Get a free [Heroku.com](http://Heroku.com) account. [Download the Heroku toolbelt](https://toolbelt.heroku.com/)
1314

14-
Follow [3Scale's instructions](https://support.3scale.net/howtos/api-configuration/nginx-proxy) on setting up an Nginx proxy. Once you've configured your sandbox proxy, you can download two Nginx config files as a zip file.
15-
You'll skip 3scale's instructions for deploying on AWS. We'll be deploying on Heroku
15+
#### Step 2: Configure 3Scale Api Proxy and download Nginx config files ####
16+
Follow [3Scale's instructions](https://support.3scale.net/howtos/api-configuration/nginx-proxy) on setting up an Nginx proxy. Once you've configured your sandbox proxy, download the Nginx config files. (Skip 3scale's instructions for deploying on AWS since we'll be deploying on Heroku)
1617

17-
18-
Example usage
19-
----------------------
18+
#### Step 3: Clone this repo ####
2019

2120
#Clone this repo, or your own fork of it (use your repo's URL obviously)
2221
$ git clone https://github.com/Taytay/api-proxy-3scale-heroku.git
2322

2423
#go into newly cloned folder
2524
$ cd api-proxy-3scale-heroku
2625

27-
Modify the nginx.conf file that 3Scale gave you to look like the nginx.conf file here.
28-
(Search for "HEROKU CHANGE" in my nginx.conf file to see the changes I made
2926

30-
Paste the contents of the generated .lua file into nginx_3scale_access.lua file
27+
#### Step 4: Rename the generated .conf files ####
28+
29+
When you unzip the config files that 3Scale gave you, they will look something like:
30+
31+
$ ls ~/proxy_configs
32+
nginx_1234567890123.conf nginx_1234567890123.lua
33+
34+
Copy them into your newly cloned folder and rename them to `nginx.conf` and `nginx_3scale_access.lua`
35+
36+
#Copy and rename the generated .conf and .lua files
37+
$ cp ~/proxy_configs/nginx_1234567890123.conf ./nginx.conf
38+
$ cp ~/proxy_configs/nginx_1234567890123.lua ./nginx_3scale_access.lua
39+
40+
41+
#### Step 5: Modify nginx.conf ####
42+
Make the following mandatory modifications to the nginx.conf file:
43+
44+
#1. Add this line to the top of the file
45+
daemon off;
46+
#2. replace 'listen 80;' with:
47+
listen ${{PORT}};
48+
#3. replace 'access_by_lua_file lua_tmp.lua;' with:
49+
access_by_lua_file nginx_3scale_access.lua;
3150

51+
See the sample **nginx.sample.conf** file for details, and for notes on other optional changes you can make.
52+
53+
#### Step 5: Create Heroku app ####
3254
Create your heroku app, using the heroku-buildpack-lua buildpack:
3355

34-
$ heroku apps:create --buildpack http://github.com/leafo/heroku-buildpack-lua.git heroku-app-name
56+
$ heroku apps:create --buildpack http://github.com/leafo/heroku-buildpack-lua.git <heroku-app-name>
3557

3658
Commit your changes to git
3759

3860
$ git add .
3961
$ git commit -m "Configuring the proxy with generated files from 3Scale"
4062

41-
Create the 3SCALE\_PROVIDER\_KEY config variable using your secret 3Scale
42-
provider key. It's in the .conf file that 3Scale generates for you
43-
44-
$ heroku config:set 3SCALE_PROVIDER_KEY=1239832745abcde
45-
4663
Deploy the app to heroku
4764

4865
$ git push heroku master
@@ -55,27 +72,34 @@ Deploy the app to heroku
5572

5673
-----> Compiled slug size: 5.0MB
5774
-----> Launching... done, v14
58-
http://heroku-app-name.herokuapp.com deployed to Heroku
75+
http://<heroku-app-name>.herokuapp.com deployed to Heroku
5976

6077

6178
Test your API proxy using an app_id and app_key you get from your 3scale control panel. More info about these credentials [here](https://support.3scale.net/howtos/api-configuration/nginx-proxy)
6279

63-
$ curl http://heroku-app-name.herokuapp.com:80/v1/word/awesome.json\?app_id\=12345678\&app_key\=12355abcdef12355abcdef12355abcdef
80+
$ curl http://<heroku-app-name>.herokuapp.com/v1/word/awesome.json\?app_id\=YOUR_USER_APP_ID\&app_key\=YOUR_USER_APP_KEY
81+
82+
{"word":"awesome","sentiment":4}%
6483

84+
Troubleshooting
85+
----------------------
86+
If something goes wrong when nginx starts up, just run `heroku logs`
87+
You should see something like:
88+
89+
2013-05-04T09:30:04.199607+00:00 heroku[web.1]: Starting process with command `start_nginx.sh`
90+
2013-05-04T09:30:10.112438+00:00 heroku[web.1]: State changed from starting to up
6591

6692

6793
Motivations
6894
-----------
69-
I wanted a free way to host 3Scale's Nginx API proxy. They have a hosted proxy,
70-
but it's only for sandbox/testing use. Nginx is very efficient, so you won't need
71-
to deploy another Heroku dyno unless you're pushing insane API traffic.
72-
That keeps this within the free usage tier on Heroku.
73-
74-
3Scale's AWS instructions are great, but it's even more appealing to me to run Nginx on Heroku because
75-
+ It's free
76-
+ More stuff is managed for me
77-
+ It's on AWS under the hood anyway
78-
+ My Nginx config files are guaranteed to be revisioned
95+
I wanted a free way to host 3Scale's Nginx API proxy. They have a hosted proxy, but it's only for sandbox/testing use. Nginx is very efficient, so you won't need to deploy another Heroku dyno unless you're pushing insane API traffic. That keeps this within the free usage tier on Heroku.
96+
97+
3Scale's AWS instructions are great, but it's even more appealing to me to run Nginx on Heroku because
98+
99+
+ It's free
100+
+ More stuff is managed for me
101+
+ It's on AWS under the hood anyway
102+
+ My Nginx config files are guaranteed to be revisioned in Git
79103

80104

81105
Credits

nginx.conf nginx.sample.conf

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
## A few minor modifications are necessary to get the generated config
66
## to work on Heroku. Search for 'HEROKU CHANGE:' in this file and make the same
77
## changes to your nginx.conf file
8-
## Note that 3Scale puts their own change markers in the generated called
9-
## "NEED CHANGE", so you will see some of those below too.
8+
## Note that 3Scale puts their own CHANGE markers in the generated file,
9+
## so you will see some of those below too.
1010

1111
## NEED CHANGE (defines the user of the nginx workers)
1212
# user user group;
@@ -49,8 +49,9 @@ http {
4949
## HEROKU CHANGE: (OPTIONAL)
5050
## 3Scale normally hardcodes the provider_key here, but if you want to avoid
5151
## checking that into source code, you can create a Heroku config
52-
## environment variable called "3SCALE_PROVIDER_KEY" and uncomment the
53-
## following line.
52+
## environment variable called "3SCALE_PROVIDER_KEY" like so:
53+
## $ heroku config:set 3SCALE_PROVIDER_KEY=1239832745abcde
54+
## Then, you can uncomment the following line.
5455
#set $provider_key "${{3SCALE_PROVIDER_KEY}}";
5556
set $provider_key "hardcoded_secret_3scale_providerkey";
5657

0 commit comments

Comments
 (0)