Menghilangkan Frontend Web Yii2 di Apache dan Nginx

Advertisement

Konfigurasi Backend

server {
    listen 80;
    server_name backend.local;
    root /var/www/yii2-test/backend/web;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* /\.(htaccess|svn|git) {
        deny all;
    }
}

Tambahkan domain ke file hosts Anda:

Advertisement
127.0.0.1 frontend.local
127.0.0.1 backend.local

Setelah konfigurasi selesai, Anda dapat mengakses frontend melalui http://frontend.local/ dan backend melalui http://backend.local/. Metode ini sangat stabil untuk produksi dan dapat dikombinasikan dengan HTTPS, caching, dan optimasi keamanan lainnya.

Artikel Terbaru