Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docu-2420] Website and API in the same Kong Gateway instance #4200

Merged
merged 3 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/styles/kong/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Okta
onboard
onboarding
opa
openresty
outbounds
passthrough
PayPal
Expand Down
9 changes: 8 additions & 1 deletion src/gateway/kong-production/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ set `KONG_LOG_LEVEL` as an environment variable:

```bash
export KONG_LOG_LEVEL=error
```
```


## More Information

* [Embedding Kong in OpenResty](/gateway/latest/kong-production/kong-openresty)
* [How to use `kong.conf`](/gateway/latest/kong-production/kong-conf)
* [How to serve an API and a website with Kong](/gateway/latest/kong-production/website-api-serving)
9 changes: 8 additions & 1 deletion src/gateway/kong-production/kong-conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ kong start -c /etc/kong.conf --vv
2016/08/11 14:53:36 [debug] database = "postgres"
2016/08/11 14:53:36 [debug] log_level = "notice"
[...]
```
```


## More Information

* [Embedding Kong in OpenResty](/gateway/latest/kong-production/kong-openresty)
* [Setting environment variables](/gateway/latest/kong-production/environment-variables)
* [How to serve an API and a website with Kong](/gateway/latest/kong-production/website-api-serving)
7 changes: 7 additions & 0 deletions src/gateway/kong-production/kong-openresty.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ nginx -p /usr/local/openresty -c my_nginx.conf
```

Kong will be running in that instance as configured in `nginx-kong.conf`.


## More Information

* [Setting environment variables](/gateway/latest/kong-production/environment-variables)
* [How to use `kong.conf`](/gateway/latest/kong-production/kong-conf)
* [How to serve an API and a website with Kong](/gateway/latest/kong-production/website-api-serving)
77 changes: 74 additions & 3 deletions src/gateway/kong-production/website-api-serving.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,77 @@
---
title: Serving a website and API from Kong

title: Serving a website and API with Kong Gateway
content-type: how-to
---

## PLACEHOLDER Serving a website and API from Kong
## How to serve both a website and APIs using {{site.base_gateway}}

A common use case for API providers is to make {{site.base_gateway}} serve both a website
and the APIs over port: `80` or `443` in
production. For example, `https://example.net` (Website) and
`https://example.net/api/v1` (API).

You can do this using a custom
Nginx configuration template that calls `nginx_kong.lua` in-line, and adds a new
`location` block that serves website alongside the Kong proxy `location`
block:

```
# ---------------------
# custom_nginx.template
# ---------------------

worker_processes ${{ "{{NGINX_WORKER_PROCESSES" }}}}; # can be set by kong.conf
daemon ${{ "{{NGINX_DAEMON" }}}}; # can be set by kong.conf

pid pids/nginx.pid; # this setting is mandatory
error_log logs/error.log ${{ "{{LOG_LEVEL" }}}}; # can be set by kong.conf
events {}

http {
# here, we inline the contents of nginx_kong.lua
charset UTF-8;

# any contents until Kong's Proxy server block
Guaris marked this conversation as resolved.
Show resolved Hide resolved
...

# Kong's Proxy server block
Guaris marked this conversation as resolved.
Show resolved Hide resolved
server {
server_name kong;

# any contents until the location / block
...

# here, we declare our custom location serving our website
# (or API portal) which we can optimize for serving static assets
location / {
root /var/www/example.net;
index index.htm index.html;
...
}

# Kong's Proxy location / has been changed to /api/v1
Guaris marked this conversation as resolved.
Show resolved Hide resolved
location /api/v1 {
set $upstream_host nil;
set $upstream_scheme nil;
set $upstream_uri nil;

# Any remaining configuration for the Proxy location
...
}
}

# Kong's Admin server block goes below
Guaris marked this conversation as resolved.
Show resolved Hide resolved
# ...
}
```

Then start Nginx:

`nginx -p /usr/local/openresty -c my_nginx.conf`


## More Information

* [Embedding Kong in OpenResty](/gateway/latest/kong-production/kong-openresty)
* [Setting environment variables](/gateway/latest/kong-production/environment-variables)
* [How to use `kong.conf`](/gateway/latest/kong-production/kong-conf)