Deploying Laravel in nginx as reverse proxy with apache

Viewed 2060

I want to deploy my laravel application in my server with nginx as reverse proxy with apache, i have a problem with URLs and page links that start with index.php. I tried the url without index.php and it works, but all links in page are with index.php. This is my configuration :

Nginx :

server {

    listen  80;
    server_name dev.exemple.com;
    root /var/www/laravel-app/public/;
    index index.php index.htm index.html;

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

    location ~ \.php {
        proxy_pass http://MY-SERVER-IP-ADDRESS:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /\. {
      deny all;
    }

    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
        log_not_found off;
    }

}

Apache

<VirtualHost *:8080>
    ServerName dev.exemple.com
    DocumentRoot /var/www/laravel-app/public/
    <Directory /var/www/laravel-app/>
        AllowOverride All
    </Directory>
</VirtualHost>
1 Answers

Hello check this solution from https://laravel.io/forum/10-25-2014-configuration-for-running-laravel-with-nginx-and-apache

server {
    listen 80;
    access_log /var/www/site.com/logs/nginx.access.log;
    error_log /var/www/site.com/logs/nginx.error.log;
    root /var/www/site.com/public_html/public;
    index index.php index.html;
    server_name site.com;

    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8080;
    }
    location ~* ^.*\.php$ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8080;
    }
    location ~ /\.(ht|git) {
            deny all;
    }

}

Related