วันอาทิตย์ที่ 26 ธันวาคม พ.ศ. 2564

ตั้งค่า https ให้ IIS

 ไปดาวโหลด

https://github.com/win-acme/win-acme/releases/tag/v2.1.20.1

แล้ว เลือก win-acme.v2.1.20.1185.x64.pluggable.zip

แตกไฟล์ และ run เลือก New Certificate ..

ใน IIS ต้อง แก้ binding เป็นชื่อ Server ด้วย


วันศุกร์ที่ 22 ตุลาคม พ.ศ. 2564

Visual Studio 2019 complied program บน Network share

 เวลา compile จะติด Security ที่ file .resx วิธีแก้ ต้องกำหนด Trust site วิธีการ ต้องไปเปิด IE และ ไปที่ internet setting

ตั้งให้เป็น Trust site



วันจันทร์ที่ 4 ตุลาคม พ.ศ. 2564

Server 2012 ทำ Reverse proxy

 ถ้าใช้ Nodejs ร่วมกับ IIS ต้องใช้ url Rewrite และ reverse proxy เพื่อ ไปทำการ ส่ง และเปิด Port ระหว่าง IIS และ Node

โดยที่ Node จะทำงานเป็น Localhost:port

ต้องไป Load โปรแกรม

http://www.iis.net/downloads/microsoft/url-rewrite

และ

https://www.microsoft.com/en-us/download/details.aspx?id=47333


สร้าง Virtual Directory สร้าง Folder เช่น /abc ต้อง convert เป็น application ด้วย และ 

สร้าง reverse proxy เวลาสร้าง ให้สร้าง ง่ายๆ ใส่ localhost และ web.com ธรรมดา แล้วค่อย มา Edit

มา ที่ localhost:port

และ อย่างลืม ตอน reverse rule ต้อง บอกให้เต็ม เช่น http://www.xyz.com/abc..

ปัญหา ถ้า ตั้ง Compress จะเกิด Error gzip

อันนี้ต้องตั้ง ค่า Rule ตาม Link นี้

https://techcommunity.microsoft.com/t5/iis-support-blog/iis-acting-as-reverse-proxy-where-the-problems-start/ba-p/846259

ดูตัวอย่าง web.config ใน คำตอบ




วันเสาร์ที่ 18 กันยายน พ.ศ. 2564

คำสั่ง Netstat ที่น่าสนใจ ถ้าเป็น mac ใช้ lsof

WINDOW
netstat -a -n -o | find ":27017" 

เอาใว้ดู port เช่น Mongo ว่ามี connection จาก process อะไร
ถ้าต้องการ kill ก็น taskkill /f <id>

netstat -a -n -o | find ":27017" /c
เป็นการ นับ ว่ามีกี port ที่ connect


OSX

ถ้าเป็น mac ใช้
lsof -i:<port>


วันพฤหัสบดีที่ 9 กันยายน พ.ศ. 2564

ให้ Mongodb connect จาก Remote ได้

 เมื่อลง Mongodb เป็น Local host แล้ววิธี แก้ให้ Mongodb connect จาก ด้านนอก

1. add user admin และ password ก่อน

    mongo

    use admin

db.createUser(
{
user: "name",
pwd: "pass",
roles: [{ role: "root", db:"admin"}]
}
)


2 แก้ mongod.conf เพื่อ ให้ access จาก network อื่นได้

sudo vi /usr/local/etc/mongod.conf
systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1 -> 0.0.0.0 หรือ IP ที่ต้องการ
3 Reboot หรือ restart services mongod

วันพฤหัสบดีที่ 1 กรกฎาคม พ.ศ. 2564

Window Server ไป เปิด Port มากกว่า 5000 เช่น Mongodb ใช้ 27017 ข้ามเครื่อง

 Window server กัน การเปิด Port มากกว่า 5000 ใน registry

https://docs.microsoft.com/en-US/troubleshoot/windows-client/networking/connect-tcp-greater-than-5000-error-wsaenobufs-10055

Regedit

  1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

  2. On the Edit menu, click New, and then add the following registry entry:
    Value Name: MaxUserPort
    Value Type: DWORD Value data: 65534

วันพฤหัสบดีที่ 27 พฤษภาคม พ.ศ. 2564

การใช้ Powershell run program และ kill program ร่วมกับ regex

 File powershell จะนามสกุล .ps1

comment ใช้ # นำหน้า

การเรียก process ใช้ & นำหน้า

มี argument ใช้    param($ตัวแปร)

ตัวอย่าง เป้นการ list process ทีเปิดport ใว้

การ filter ให้ใช้ regex 



# kill process select port

Write-Output "Kill process at port"

param ($port)

$foundProcesses = netstat -ano | findstr :$port

$activePortPattern = ":$port\s.+LISTENING\s+\d+$"

# search between number and string

$pidNumberPattern = "\d+$"

# if search between number use "\d+\d"

#If 

IF ($foundProcesses | Select-String -Pattern $activePortPattern -Quiet) {

  $matches = $foundProcesses | Select-String -Pattern $activePortPattern

  $firstMatch = $matches.Matches.Get(0).Value

#Match by regex

  $pidNumber = [regex]::match($firstMatch, $pidNumberPattern).Value

  taskkill /pid $pidNumber /f

}


อีกตัวอย่าง เอา title ของ process และมา kill. โดยใช้ Get-Process

#& TASKLIST /v /fo table | findstr "PCS"
param ($port)

$findV = Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle -AutoSize | findstr /I 'PCS' | findstr $port
IF($findV){
$pid1= [regex]::match($findV,"\d+\d").Value

$pid1
#kill it
 taskkill /pid $pid1 /f
}