Nginx Config for Laravel Application in sub folder

To run Laravel Application on a subfolder of a website, use the following configuration. If you run the Laravel application as the main site, see Nginx Config for Laravel Application

# subFolderApp1

location /subFolderApp1 {  
    alias /home/yorudomain.com/html/subFolderApp1/public;  
    try_files $uri $uri/ @subFolderApp1;
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/run/php/php7.2-fpm-torrentp.sock;
    }
}  

location @subFolderApp1 {
    rewrite /subFolderApp1/(.*)$ /subFolderApp1/index.php?/$1 last;
}

# end subFolderApp1

Here you place the Laravel application in a subdirectory “subFolderApp1”.

Example

server {
    server_name serverok.in www.serverok.in;
    root /home/serverok.in/html/;
    index index.php index.html index.htm;
    client_max_body_size 1000M;
    proxy_read_timeout 600s;
    fastcgi_read_timeout 600s;
    fastcgi_send_timeout 600s;

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


    # service

    location /service {  
        alias /home/serverok.in/html/service/public;  
        try_files $uri $uri/ @nested1;
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/run/php/php7.2-fpm-torrentp.sock;
        }
    }  

    location @nested1 {
        rewrite /service/(.*)$ /service/index.php?/$1 last;
    }

    # end service

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_intercept_errors on;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_pass unix:/run/php/php7.2-fpm-torrentp.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/serverok.in/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/serverok.in/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = www.serverok.in) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = serverok.in) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name serverok.in www.serverok.in;
    return 404; # managed by Certbot
}

Back to Nginx

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *