text stringlengths 0 13.4k |
|---|
121 |
Deploy with Docker |
At the beginning of this chapter, I mentioned that you should use a |
reverse proxy like Nginx to proxy requests to Kestrel. You can use |
Docker for this, too. |
The overall architecture will consist of two containers: an Nginx |
container listening on port 80, forwarding requests to the container you |
just built that hosts your application with Kestrel. |
The Nginx container needs its own Dockerfile. To keep it from |
conflicting with the Dockerfile you just created, make a new directory in |
the web application root: |
mkdir nginx |
Create a new Dockerfile and add these lines: |
nginx/Dockerfile |
FROM nginx |
COPY nginx.conf /etc/nginx/nginx.conf |
Next, create an nginx.conf file: |
nginx/nginx.conf |
events { worker_connections 1024; } |
http { |
server { |
listen 80; |
location / { |
proxy_pass http://kestrel:80; |
proxy_http_version 1.1; |
proxy_set_header Upgrade $http_upgrade; |
proxy_set_header Connection 'keep-alive'; |
proxy_set_header Host $host; |
proxy_cache_bypass $http_upgrade; |
} |
122 |
Deploy with Docker |
} |
} |
This configuration file tells Nginx to proxy incoming requests to |
http://kestrel:80 . (You'll see why kestrel works as a hostname in a |
moment.) |
When you make deploy your application to a production |
environment, you should add the server_name directive and |
validate and restrict the host header to known good values. For |
more information, see: |
https://github.com/aspnet/Announcements/issues/295 |
Set up Docker Compose |
There's one more file to create. Up in the root directory, create docker- |
compose.yml : |
docker-compose.yml |
nginx: |
build: ./nginx |
links: |
- kestrel:kestrel |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.