_
|
|-- docker-compose.yml
|
|-- nginx
| |
| \_ default.conf
|
|-- nodejs
| |
| \_ index.js
|
\__ static
|
\_ test.txt
Created
July 31, 2018 10:22
-
-
Save ultim8k/6bbedae79bad9a0a3c38f21bcc1b6d91 to your computer and use it in GitHub Desktop.
Docker setup for node.js with nginx proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.3" | |
services: | |
nginx: | |
image: nginx:alpine | |
ports: | |
- "8000:80" | |
- "443:443" | |
volumes: | |
- ./static:/srv/www/static | |
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf | |
depends_on: | |
- nodejs | |
nodejs: | |
image: node:alpine | |
environment: | |
NODE_ENV: production | |
working_dir: /home/app | |
restart: always | |
volumes: | |
- ./nodejs:/home/app | |
command: ["node", "index"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
root /srv/www; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
location / { | |
try_files $uri @nodejs; | |
} | |
location @nodejs { | |
proxy_pass http://nodejs:3000; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const port = 3000; | |
const requestHandler = (request, response) => { | |
console.log(request.url); | |
response.end('Hello Node.js Server!'); | |
} | |
const server = http.createServer(requestHandler); | |
server.listen(port, (err) => { | |
if (err) { | |
return console.log('something bad happened', err); | |
} | |
console.log(`server is listening on ${port}`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi there! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment