2

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 Answer 1

1

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;
    }

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.