Deploying Advanced Template to AWS Elastic Beanstalk

My mistake, I just redid method 1 and it indeed redirects to domain.com/backend/site/login without the web.

I miswrote in my previous post.

I left the config changes from method 2 in place, but they make no difference.

Please let me know what to check/try next.

It is the expected behavior that the first backend access is redirected to “backend/site/login” because the backend index page requires a valid user login. Did you register some user in the frontend? Try to register some user in the frontend and login with it, then you will be able to access the backend index page.

When you take the 1st method, there should be no need to do extra nginx configurations for the backend. You should be able to think that there’s only frontend, no backend at all.

Hmm, but should it not at least take me to the login page for the backend? Instead it gives me a 404 error.

I’ll try this in a bit (traveling) and need to finish setting up the site or disabling some things to log in (Capthas and stuff).

What do you mean by “it”? Is it a valid URL like "http://domain.com/backend" or an invalid URL like "http://domain.com/backend/web"? It’s very natural that an invalid URL ends in a 404 error.

And just as I suggested in another thread, take a look at kartik-v’s Yii2 Practical-A-App and probably you will like it.

My apologies for not being clear. The url shows domain.com/backend/site/login however, what is actually displayed is a blank 404 Not Found page (nginx/1.20.0)

This is for apache. I actually had no problem getting this setup in apache on my local machine, but I’d like to run nginx for full deployment.

I see. So what do you see in nginx’s error log about it? Or, application logs in “runtime” folder may have some information.

Oh is it? I don’t believe it and will check it.

[EDIT]
Yii2 Parctical-A-App works with nginx.

[EDIT 2]
Oh, I’m sorry. The document above doesn’t tell what to do for a single domain. Hmm…

Alright, just pulled the nginx error.log. This is what it shows:

2021/09/07 04:01:02 [error] 5643#5643: *98 open() "/var/www/html/frontend/web/backend/site/login" failed (2: No such file or directory), client: 45.17.74.222, server: , request: "GET /backend/site/login HTTP/1.1", host: "rof-env.eba-w4zn6ugp.us-east-2.elasticbeanstalk.com"

As you can see, it’s simply appending backend/site/login. This is using method 1 with a simple symbolic link. I had noticed this before and is why I went with method 2 (and others like it).

Still, no luck.

Did you enable the pretty url? Try with it disabled.

And btw, I even tried an absolute symbolic link with the command below

ln -s /var/www/html/backend/web backend

Got the exact same behavior and the exact same error response.

Seems to be that nginx will not go outside the root directory… and I don’t know why

Give me a sec…

Voila! Disabling PrettyUrl and I am able to access the backend now.

Sigh… I thought about disabling pretty url a while ago, but I didn’t think it would be the source of my problem. Figured it had to be something I was doing wrong.

Now the question is, is there something that needs to happen with prettyUrl? I’d really like to use it if possible.

OK, I think I got a solution for enabling PrettyUrl.

Try adding these lines in the nginx configuration.

    location /backend {
        try_files $uri $uri/ /backend/index.php$is_args$args;
    }
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

instead of the existing line:

    try_files $uri $uri/ /index.php$is_args$args;

Url manager configurations can be simple enough:

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],

This should work for both frontend and backend.
I didn’t have to set baseUrl or scriptUrl for the backend.

THIS WORKED! THANK YOU SO MUCH!

I have spent more than a week on this problem. Where should I create a resource for this in case others have the same issue?

I think you can revise the wiki.

1 Like

Wiki has been updated! Thanks again!

1 Like

hey last question (I hope),

How would I direct a subdomain to the backend?

Nevermind, I figured it out. Needed to create another “server” configuration for the subdomain. Ironically, this is actually easier than what I was trying to do up above.

1 Like