Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure nginx correct for both laravel and yii project?

Tags:

nginx

yii

Im trying to configure nginx to serve laravel and yii project on same domain. My laravel project is working fine. Yii project also working but assets folder on yii project is giving err_aborted not found 404. All js css ... files are not found

server {

server_name mydomain.com;
index index.html index.php;
charset utf-8;
set $base_root /var/www;
# App 1 (main app)
location / {
    root $base_root/telemele/public;
    try_files $uri $uri/ /index.php?$query_string;
    error_log /var/log/nginx/telemele.notice.log notice;
    error_log /var/log/nginx/telemele.error.log error;

    location ~* ^/index\.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/telemele/public/index.php;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
}

# App 2
location ~* /mahabat {
    alias $base_root/html/backend/web;
    try_files $uri $uri/ /mahabat/index.php?$query_string;

    error_log /var/log/nginx/mahabat.notice.log notice;
    error_log /var/log/nginx/mahabat.error.log error;

    location ~* ^/mahabat/index\.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/html/backend/web/index.php;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
location ~* \.css|\.js|\.jpg|\.jpeg|\.png|\.gif|\.swf|\.svg|\.tiff|\.pdf$ {
 try_files $uri =404;
 }

location ~ ^/assets/.+\.php(/|$) {
        deny all;
    }
}

# Files
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

# Error
access_log off;
rewrite_log on;

# Disable .htaccess access
location ~ /\.ht {
    deny all;
}
}

What am i doing wrong? How to make nginx not to abort assets folder files? why it is giving not found?

like image 624
merdan Avatar asked Feb 05 '20 13:02

merdan


1 Answers

There might be a missing .htacces file at the frontend/web directory. If you have the same problem, I recommend you to use this

like image 181
Mahri Ilmedova Avatar answered Nov 17 '22 11:11

Mahri Ilmedova