2

I'm trying to configure nginx so that I can run a main website out of /, and then to also run a new Laravel site out of /myapp. I've already gotten rid of the need for /myapp/public in the app itself (the public folder part of it), so all I need is to serve up that /myapp folder correctly. Right now I can access the homepage / correctly, but the new Laravel app at /myapp throws a 404: nginx/1.4.6 (Ubuntu). I've posted my nginx config below. This is running on Ubuntu on AWS, if that helps.

Thanks!

[UPDATE!] - I've now got everything working out of both the root dir, and the /myapp Laravel app folder, except that resources do not seem to work. For instance http://example.com/myapp/public/css/app.css 404's, as do other js and css files. Unsure what's causing this. I've made sure the public folder has full permissions, at least for testing purposes. Have also checked the owner/group, which is the same as all my other files that serve fine, ubuntu:ubuntu.

server {

listen  80;
server_name *.example.com;
set $root_path '/usr/share/nginx/html/';
root $root_path;

index index.php index.html index.htm;

try_files $uri $uri/ @rewrite;

location @rewrite {
    rewrite ^/(.*)$ /index.php?_url=/$1;
}

location ~ \.php {

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index /index.php;

    include /etc/nginx/fastcgi_params;

    fastcgi_split_path_info       ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
    allow all;
}

rewrite ^/myapp/?(.*)$ /myapp/index.php?$1 last;

location /myapp {
    allow all;
}

location ~ /\.ht {
    deny all;
}

}
carbide20
  • 1,717
  • 6
  • 29
  • 52
  • I've added an edit above, as well as a new config file. Please check the update before responding! Thanks :) – carbide20 Sep 15 '15 at 11:48

1 Answers1

2

I finally solved it, after a couple days of tinkering. It now loads the main site, the child Laravel site, and all resources correctly. Here's the final config, for reference.

server {

    listen  80;
    server_name *.example.com;
    set $root_path '/usr/share/nginx/html/';
    root $root_path;

    index index.php index.html index.htm;

    try_files $uri $uri/ @rewrite;

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

    location ~ \.php {

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        allow all;
    }

    location ~* ^/myapp/?(.+)/(css|img|js|flv|swf|download)/(.+)$ {
        allow all;
    }

    location ~ \.css {
        add_header  Content-Type    text/css;
    }

    location ~ \.js {
        add_header  Content-Type    application/x-javascript;
    }

    location /myapp {
        allow all;
        rewrite ^/myapp/?(.*)$ /myapp/index.php?$1 last;
    }

    location ~ /\.ht {
        deny all;
    }

}

carbide20
  • 1,717
  • 6
  • 29
  • 52