0

i am on laravel 8, php 8.1.29 and i am trying to move my current progject from php-fpm to laravel octane, follwoing the instructions from laravel documentations i am able to install and enable octane with swoole, but i am facing an issue, like i am not able to open web pages (apis are working fine), when i try with url on browser "domain.com" it show a popup to download index.php from public folder.

i am using following conf in nginx

    default upgrade;
    ''      close;
}
 
server {
    listen 80;
    listen [::]:80;
    server_name domain.com;
    server_tokens off;
    root /home/dir/public;
 
    index index.php;
 
    location /index.php {
        try_files /not_exists @octane;
    }
 
    location / {
        try_files $uri $uri/ @octane;
    }
 
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
 
    access_log off;
    error_log /dir/to/error/log;
 
    error_page 404 /index.php;
 
    location @octane {
        set $suffix "";
 
        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }
 
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
 
        proxy_pass http://127.0.0.1:8000$suffix;
    }
}

enter image description here

5
  • hi @Muhammad Anas. Could you kindly post any error that appears? Commented Jun 21, 2024 at 13:56
  • No error, its just showing popup to download the index file Commented Jun 21, 2024 at 14:10
  • ok it's clear what's happening, your nginex is busily asking for the file. octane needs another daemon besides nginex, run this php artisan octane:start --server=swoole --host=0.0.0.0 --port=8000 run the command and use proxypass with nginx upstream not ` root /home/dir/public; index index.php; ` Commented Jun 21, 2024 at 14:14
  • doc: laravel.com/docs/11.x/octane#serving-your-application Commented Jun 21, 2024 at 14:16
  • @GianfrancescoAurecchia i am getting 302 status code when i am trying to hit a web url, i think there's something i am missing Commented Jun 21, 2024 at 18:20

1 Answer 1

1

I hope this can help. I use the same stack. this is my nginx skeleton setup


#make a laravel upstream

upstream laravel {
    server laravel.test:80; # in your case i suppose http://127.0.0.1:8000
}


#make server

server {
    listen              80;


    # mathc all routes and proxy to laravel upstream
    location / {
        proxy_pass      http://laravel;
    }
}


I advise you to try this configuration first and then add all your nginx custom rules one by one, so you can find out what's wrong

EDIT 1

to make the stack you selected work you need to do the following steps,

1) go to your laravel folder and run the following command:

php artisan octane:start --host=0.0.0.0 --port=8000

2) Change the nginx configuration


upstream laravel {
    server localhost:8000;
}

#make server

server {
    listen 80;
    listen [::]:80;
    server_name domain.com;

    location / {
        proxy_pass http://laravel;
    }
}


3) restart nginx

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

1 Comment

I get a connection refused error when trying this.

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.