Hi, I’ve started running my project by using yii2-app-basic. I’m using nginx as a webserver, and I’m trying to host my project at /site rather than at /.
My nginx configuration is working and showing me the project at http://localhost/site, but all the links generated by Yii point to http://localhost. I’ve also set the ‘baseUrl’ in my request component configuration to ‘/site’.
Anything I’m doing wrong? Is there any way to tell Yii to generate all the links properly?
Can you show us in which directory you have installed your yii2-app-basic? Or, in other words, what is the path to the 'index.php' entry script? For example, I have a yii2-app-basic project installed in '/var/www/diary' (production server) and 'C:\data\diary (development environment), and their paths to the entry script are '/var/www/diary/web/index.php' and 'C:\data\diary\web\index.php' respectively.
And then what do you have for server configuration in your nginx config file? My server config is something like the following:
server {
charset utf-8;
client_max_body_size 128M;
listen 443 ssl http2; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name diary.softark.net;
root /var/www/diary/web;
index index.php;
...
As you see, 'root /var/www/diary/web;' specifies the directory where my index.php is located.
And with this configuration I can access my diary app by the URL of https://diary.softark.net/, not https://diary.softark.net/web/.
This is based on the article of PHP Apps in a Subdirectory in Nginx and is simplified and modified to your environment. I’ve tested it and confirmed that it works fine for me, so I hope it will work for you, too.