Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chojisan's avatar

Configure Laravel on Ubuntu with Nginx reverse proxy apache

I setup a local web server using Ubuntu 14.04 with a NGINX setup as reverse proxy for apache2. I can't run Laravel correctly. What is the right configuration in nginx for laravel to work? thanks

0 likes
3 replies
dgraver's avatar

I have a similar set up where Laravel is running behind a nginx reverse proxy. My problem is that the URL Generator does not use the APP_URL config in .env for generating URLs, so a lot of my assets and things are incorrect.

E.g. http://localhost/xcharge points to nginx server, which then passes it on to Laravel server with Apache. The apache config has /var/www/public as the DocumentRoot (no slug), so when Laravel generates a URL it uses "/" as the base (since that's what it interprets since it came from reverse proxy) instead of using the APP_URL config to generate URLs. Any advice for getting L5 to use it? I think L3 would use the config url, but not L5.

Here's the nginx config for it:

# proxy for xcharge
location /xcharge/ {
    proxy_pass http://172.17.0.10:80/;

    # rewrite redirect / location headers to match this subdir
    proxy_redirect default;
    proxy_redirect / $scheme://$http_host/xcharge/;

    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $remote_addr;
}

# requests without trailing slash will be forwarded to include slash
location = /xcharge {
    return 301 $scheme://$http_host$uri/$is_args$args;
}

Please or to participate in this conversation.