5
Wombat
3y

I have an nginx question.

Is it possible to send example.com/ requests to a Laravel app and send all other requests to an WordPress app?

Comments
  • 7
    Do you mean:
    example.com/ -> lavarel
    example.com/bla -> wordpress

    This case is in the docs: https://nginx.org/en/docs/...
  • 3
    I exactly meant this case. I will check that. Thanks for the link
  • 3
    I kinda get it, but can't make it work. ~_~
  • 0
  • 0
  • 4
    @Wombat Keep trying!
  • 1
    It works on my end.
  • 1
    So far i had only one usecase which ngnix couldn't solve - proxy rules for udp traffic. For all regular web routing, caching, proxy problems nginx answer has been yes.
  • 0
    @Avimelekh I've spent hours trying to only catch example.com/ and specify the Laravel root for it. All my efforts ended in 403 or 404 or just the WordPress site... 😭
  • 2
    @Wombat it should look like this:

    location = / {
    root /lvarelroot; # filesystem path
    fastcgi_param SCRIPT_FILENAME /lavarelindex.php; # filesystempath
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;
    #Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    fastcgi_param front_controller_active true;
    fastcgi_pass fpm;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
    }

    location / {
    [fastcgi config wordpress]
    }
  • 0
    I probably tried that. Will check it later. Thanks 😌
  • 0
    https://google.com/amp/s/...

    Scroll to location block, regex should solve your problem. Issues will a rise from pathing after first slash, for example if both apps have same path, i would seperate these two, by giving some prefix for each using rewrite in nginx. However rewrite will introduce you to new redirection problems, which mostly can be solved but can become tricky.
  • 1
    Did you manage to get it working?
    I have a similar wcnario where root route goes to www folder and API route go to a docker container.

    If you still didn't get it working let me know I'll share my config. It's just I'm not near my laptop to share now 😅
  • 1
    @gitpush actually I gave up. 😣
  • 1
    @Wombat This is the config I use: https://pastebin.com/fpv5Lth5

    It redirects to three docker containers and one statically served web page. It should be the same in your case, if you are not using containers then I assume you need to set root in each block.
  • 1
    @gitpush thank you very much. I appreciate your help. 😌😘
  • 1
    @Wombat your welcome good luck 🙏
Add Comment