Tag Archive เอ็นจินเอ็กซ์

Byphunsanit

Nginx: phpMyAdmin reverse proxy

จาก Ubuntu: ติดตั้ง phpMyAdmin แบบปลอดภัย จะเพิ่มความปลอดภัยอีกชั้นโดยการเอา Nginx มาครอบ phpMyadmin ไว้อีกชั้น เพื่อที่จะจัดการบางอย่างได้และจะเปิด port ที่เข้าจากข้างนอกได้แค่ port 80 เท่านั้น โดยตั้งให้เอ็นจินเอ็กซ์เป็น reverse proxy ของ Apache อีกชั้น

  1. ติดตั้ง Nginx ถ้ายังไม่ติดตั้งโดยคำสั่ง
    sudo apt-get install nginx
  2. สร้างไฟล์ config nginx เช่น
    /etc/nginx/sites-available/plusmagi.com.phpmyadmin.conf
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name v771s.plusmagi.com;
    http2 on;

    access_log /var/log/nginx/plusmagi.com.phpmyadmin-access.log;
    error_log /var/log/nginx/plusmagi.com.phpmyadmin-error.log error;

    ssl_certificate /etc/letsencrypt/live/v771s.plusmagi.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/v771s.plusmagi.com/privkey.pem;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;

    client_max_body_size 20M;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name v771s.plusmagi.com;

    client_max_body_size 20M;

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt;
        allow all;
        default_type "text/plain";
        try_files $uri =404;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

ที่ต้องแก้ คือ

  1. domainใน บรรทัดที่ 4,
  2. subdomainใน บรรทัดที่ 10, 11, 29
  3. port ในบรรทัดที่ 18

โดยทำให้ตรงกับที่ตั้งไว้ใน Apache config ในขั้นตอนที่แล้ว

อ่านเพิ่มเติม