Skip to content

Instantly share code, notes, and snippets.

Nginx proxy ใน docker-compose.yml อ้างอิงจากงานที่ทำอยู่

มันเริ่มจากงาน React ตัวแรกของผม ที่อยากจะลอง แยก API กับ Frontend มันออกมา OK ใช้งานได้แต่ ……..

ปัญหา: งานนี้เดิมใช้ node เป็นตัว proxy ไปยัง server API แต่กับติดปัญหา error timeout เมื่อ User ส่งข้อมูลที่ขนาดใหญ่กว่าที่เราคิดเอาไว้ (ใหญ่มากๆ …… 1000 เท่าได้) เมื่อเราลองทดลองส่งข้อมูลขนาดนั้นดูบ้าง ก็ได้รับ error timeout ผ่านใน 5 วินาที แต่ในเครื่อง Dev สามารถส่งได้สำเร็จ ข้อแต่ต่างระหว่างเครื่อง Dev กับ Sever คือ proxy

มันทำให้ผมมีความคิดว่า “ต้อง upgrade proxy ไปยัง อะไรที่ดีกว่า” ไม่ว่าความคิดนี้จะถูกหรือจะผิด แต่ผมก็ได้ลงมือสร้าง nginx server และให้มัน proxy ไปยัง API, API-v2 และ Frontend เพื่อทดสอบความคิดของผม

สมมติฐาน: node proxy มีปัญหา และ nginx proxy จะทำได้ดีกว่า จากความนิยม

การแก้ไข:

@M4R14
M4R14 / ghost-stack.yml
Last active May 12, 2019 14:13
สร้าง Blog ส่วนตัวด้วย Ghost CMS - http://vachirawit.com/sraang-blog-swntawdwy/
# by default, the Ghost image will use SQLite (and thus requires no separate database container)
# we have used MySQL here merely for demonstration purposes (especially environment-variable-based configuration)
version: '3.1'
services:
ghost:
image: ghost:2-alpine
restart: always
ports:
- 80:2368
@M4R14
M4R14 / SOL-A.js
Last active May 12, 2019 14:19
วิธีใส่ Puppeteer เข้าไปใน Jest เพื่อทำ UI Testing ในโหมด headless browser อย่างง่าย… / sol.A - http://vachirawit.com/puppeteer-and-jest-testing-headless-browser/
const puppeteer = require('puppeteer');
const Chrome = async ({ STEP }) => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await STEP(browser, page);
browser.close();
}
@M4R14
M4R14 / SOL-B.js
Last active May 12, 2019 14:20
วิธีใส่ Puppeteer เข้าไปใน Jest เพื่อทำ UI Testing ในโหมด headless browser อย่างง่าย… - http://vachirawit.com/puppeteer-and-jest-testing-headless-browser/
const puppeteer = require('puppeteer');
const _30s = 1000 * 30;
const _1m = 1000 * 60;
const _5m = _1m * 5;
describe('Open Url: Google, Github.', () => {
var browser, page;
beforeEach(async () => {
@M4R14
M4R14 / docker-compose.yml
Last active May 13, 2019 18:00
ติดตั้ง Gitlab ไว้ใช้ใน ออฟฟิศ - http://vachirawit.com/setup-gitlab-for-office/
version: '3'
services:
gitlab:
image: gitlab/gitlab-ee:latest
restart: always
hostname: <hostname>
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.gmail.com"

Open Docker on mac:

$ open /Applications/Docker.app

Open Project @bkksol:

$ docker-compose up

Stop all containers:

@M4R14
M4R14 / docker-compose.yml
Last active November 15, 2019 06:29
รัน gogs ทำ Git Server เอง
version: "3.7"
services:
gogs:
image: gogs/gogs
ports:
- "10022:22"
- "10080:3000"
volumes:
- ./gogs:/data
from ezprinting import PrintServer, Printer, PrintJob
import json
with open('asdasdasd.pdf', 'rb') as f:
content = f.read()
# If we want CUPS on localhost...
print_server = PrintServer.cups()
# the rest of the code is the same for either cups or GCP...
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
namespace Printer
{
class Program
{
protected static String printerName = "Brother MFC-J3930DW";
# pin3 install numpy
# pin3 install BeautifulSoup
import requests
import numpy
from bs4 import BeautifulSoup
def getContent(url):
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')