NGINX: Multiple CI Apps on a Single Domain Not Working |
07-04-2024, 10:44 PM
(This post was last modified: 07-04-2024, 11:46 PM by sillyquota. Edit Reason: Changed topic to something more specific )
How can I make https://api.domain.com/appname show the contents of /home/www/api.domain.com/appname/public
+ and retain the ability to show /home/www/api.domain.com/index.php at https://api.domain.com/ + and retain the ability to host other unrelated php-based api backends at https://api.domain.com/anotherAPIthing or any other arbitrary URI structure on api.domain.com? I have CI4.5.3 installed at /home/www/api.domain.com/appname. My domain (api.domain.com) root is /home/www/api.domain.com. I do not want to change the main(outer-most) docroot of https://api.domain.com/ because I would like to have multiple api backends hosted there (for example api.domain.com/appname, api.domain.com/anotherapp, etc..). If I change the main docroot then I can only use https://api.domain.com for my 'appname' app. I've tried so many different configurations I can't even remember all of them... Here is my current configuration (which does not work for me) Code: server { With the above configuration I get the following error when trying to access my CI app via https://api.domain.com/appname: Code: 2024/07/05 00:29:39 [error] 72934#72934: *14 "/home/www/api.domain.com/appname/public/appname/index.php" is not found (2: No such file or directory), client: REDACTED, server: api.domain.com, request: "GET /appname/ HTTP/2.0", host: "api.domain.com" I'm not very good at nginx configurating but I've tried using rewrites as well and they always end up with infinite redirects or attempting to access "/home/www/api.domain.com/appname/public/appname/public/index.php" or "/home/www/api.domain.com/appname/public/appname/appname/appname/appname/appname/" etc
Basically you need to use two different <VirtualHost> entries in your virtual host configuration file.
To my knowing (and if it is okay to do so I don't do it) it is not possible to have two ServerName entries in ONE <VirtualHost> directive. Further I'd first get rid of all the 443 related stuff for testing - its just confusing and you can add that, configure and test it later when the rest is up and running. The two <VirtualHosts> entries each need to have a <DocumentRoot> of course and an own ServerName part which is used to identify the host. I'd also put much of the stuff you posted in the main configuration file. It makes things easier to configure, files slicker and many configuration settings need to be defined once only anyway. Hope that helps.
The only absolute knowledge attainable by man is that life is meaningless. (Tolstoi)
This is a snippet of my apache2.conf on my remote server with some personal remarks.
Code: # Computername and port so the computer can identify itself. The system Apache This is the vhost to the apache2.conf above: Code: # --- Vhosts configuration -----------------------------------------------------#
The only absolute knowledge attainable by man is that life is meaningless. (Tolstoi)
Hey thanks for the replies! Apologies for the late response, I've been extremely busy of late.
I did however set aside some time to really think this through and I was able to find the solution to my issue. Unfortunately I don't have the complete config file as my server is having issues with the hard drive but this is the resolution I implemented: Code: server { NOTE: Some of this was reconstructed from memory because my server is offline for repair so YMMV, but I'm pretty sure this is how I got it working. I imagine this might be a bit of an edge-case since this places the approot within the webserver docroot (against most recommendations) and requires explicit location-blocking of sensitive directories. This was as much a learning exercise as it was a necessity for my situation
(07-10-2024, 02:10 PM)bogus Wrote: Basically you need to use two different <VirtualHost> entries in your virtual host configuration file. I had this problem too, it drove me crazy. Thanks for this helpful information, I solved the problem that was bothering me for a long time. |
Welcome Guest, Not a member yet? Register Sign In |