Nginx + magento 2 multisite setup with sub directory - php

I have Magneto 2 installed on the server and the main site is working with www.example.com and loading Magneto 2 root directory. Now have created sub-folder called "ksa" inside Magento root directory.
I need to load main site with "ksa"
For example
example.com/test.php to example.com/ksa/test.php
My nginx configuration
location ~ /ksa/ {
rewrite ^/ksa/$ http://example.com/ permanent;
}

Related

NGINX Setup with WordPress Multisite

I wanted to know the configuration for WordPress Multisite when the main site is in the root and the others in /site-name/
For example:
Main website: http://www.example.com/ Second website: http://www.example.com/second-site/ Third site: http://www.example.com/thrid-site/
I looked for the setting, but I only found it with subdomains.
Let's say your folder structure is as follows:
/root_folder/*
/root_folder2/second-site/*
/root_folder3/third-site/*
Then you need:
server {
server_name www.example.com;
root /root_folder/;
location / {
# code
}
location /second-site {
root /root_folder2/;
# code
}
location /third-site {
root /root_folder3/;
# code
}
}
It's important not to add the /second-site and /third-site in the root directive as Nginx will automatically add requested subpaths to the root path at request.
If your folder structure is as follows:
/root_folder/*
/root_folder/second-site
/root_folder/third-site
You only need
server {
server_name www.example.com;
root /root_folder/;
location / {
# code
}
}
And Nginx will do the rest for you.

How to automate deployment of ngnix configuration on Amazon AWS?

i have a created project using symfony 5.
For hosting website i am using amazon AWS.
Amazon AWS instance is using nginx.
Everytime i deploy code using Elastic beanstalk i have to add following lines to the etc/nginx/nginx.conf file
location / {
try_files $uri $uri/ /index.php?$args;
}
if i don't add following configuration and don't restart nginx server then only page of my website is visible . Whenever i try to open another page of website excepts homepage i get following error :
404 Not Found
nginx/1.18.0
How can i automate deployment of the ngnix configuration whenever i upload code using elasticbeanstalk ?
If you want to modify your nginx configuration, you should modify your Configuration Files by extending ElasticBeanstalk as explained here
I will assume you are using Amazon Linux 2, if not the ElasticBeanstalk is working completely differently as documented here.
Elastic Beanstalk (using Amazon Linux 2) will automatically look for a .platform directory at the root of your zip file.
By adding .platform/nginx/conf.d/elasticbeanstalk/php-custom.conf with the following content, you should be good to go (assuming you are using the default configuration). Note that you could overwrite the nginx.conf by adding this file .platform/nginx/nginx.conf to your project, but since what you want to do is fairly simple, I would only add a file that will be automatically loaded by nginx.
location / {
try_files $uri $uri/ /index.php?$args;
}
So your project tree should look something like this.
project root
├── .platform
│   └── nginx
│   └── conf.d
│   └── elasticbeanstalk
│   └── php-custom.conf
└── your project files

index.php not loading from ubuntu server VM (nginx & sftp)

I'll try to be short as it can get bloated.
I set up an ubuntu server 20.04 VM on an Oracle vbox.
I installed nginx, php7.4, Xdebug 3.
I configured everything properly for remote debugging and sftp ( I use PHPstorm), I forwarded the ports and customized my local hosts file.Everything works except...
when loading HTTP://127.0.0.2 it loads the default nginx landing page.My index.php file is uploaded in the root /var/www/my_domain folder through sftp. I created the server block for my_domain.
Still won't work. I am new to this so I am missing something.
If you need more info please request.
Any help appreciated!
Vhost config ( server block in nginx) - php-projects being my current domain and containing index.php:
server {
listen 80;
listen [::]:80 ipv6only=on;
root /var/www/php-projects;
server_name php-projects www.php-projects;
location / {
try_files $uri $uri/ =404;
}
error_log /var/log/nginx/debug.log debug;
}
Network settings from Vbox:
PS. I have tried :
How to set index.html as root file in Nginx?
and
Rewrite rule for the root file in nginx?
with no success.
"I configured everything properly for remote debugging and sftp"
Please post your xdebug configuration.
"when loading HTTP://127.0.0.2"
From where ? Host machine or VM?
"My index.php file is uploaded in the root /var/www/my_domain folder
through sftp."
Please post your nginx vhost configuration
"I created the server block for my_domain"
Where? Post the path to the file where you have done this

How to change root directory for PHP azure website?

I have created a PHP website on azure using app services. I use continuous deployment through bitbucket. I need to point the website to public folder in my code to run the app as it is built with zend framework.
After some search, was not able to find how to change the folder where the server points for default directory.
Go to Azure Web apps settings -> Application Settings -> Virtual Applications and directories and setup the physical path of the new folder. Also check the Application checkbox.
Restart the web app once.
There are a few scenarios possible:
You run a Windows App Service
You run a Linux App Service with PHP 7.4 or less
You run a Linux App Service with PHP 8
In the first scenario (Windows App Service) you can go to the App Service > Settings > Configuration blade you need to select the tab "Path Mappings" where you can set the Virtual Applications paths as follows: "/" maps to "site\wwwroot\public".
In the second scenario you can use the .htaccess solution described by #Ed Greenberg, even though for Zend Framework I suggest to use the following settings:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
For the third scenario you have a bit more of a challenge since Apache was replaced by Nginx and the rewrite rules no longer apply. Please see my detailed blog article "PHP 8 on Azure App Service" on how to solve this and other challenges with the new Azure App Service for PHP 8.
Good luck and let me know if it solved your problem.
For PHP 8.0 with nginx I use startup.sh script placed in the root directory of the project. startup.sh contains the following line:
sed -i 's/\/home\/site\/wwwroot/\/home\/site\/wwwroot\/public/g' /etc/nginx/sites-available/default && service nginx reload
You need to add "startup.sh" as Startup Command in General Settings. Now "public" dir is your root directory.
The correct answer in 2021 (for Laravel, and probably other frameworks with a /public directory) is to put an extra .htaccess in the webroot directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Credit to Azure Web App - Linux/Laravel : Point domain to folder
Finally I've found Laravel documentation how to make it work with Azure. To be more precise - PHP8 + NGINX. Here is the article link - https://azureossd.github.io/2022/04/22/PHP-Laravel-deploy-on-App-Service-Linux-copy/index.html
Hope it will be useful :-)
PHP 8 (NGINX)
PHP 8 on Azure App Service Linux use NGINX as the Web Server. To have NGINX route requests to /public we’ll have to configure a custom startup script. We can grab the existing default.conf under /etc/nginx/sites-available/default.conf and run cp /etc/nginx/sites-available/default.conf /home. This will copy the default.conf we need into /home so we can download it with an FTP client or any other tool that allows this.
This default.conf has the following line:
root /home/site/wwwroot;
We need to change it to the following:
root /home/site/wwwroot/public;
Next, under the location block we need to change it from:
location / {
index index.php index.html index.htm hostingstart.html;
}
to the following:
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /index.php?$args;
}
Now configure your actual startup.sh bash script. Note, the file name is arbitrary as long as it is a Bash (.sh) script. Configure the file along the lines of the below:
#!/bin/bash
echo "Copying custom default.conf over to /etc/nginx/sites-available/default.conf"
NGINX_CONF=/home/default.conf
if [ -f "$NGINX_CONF" ]; then
cp /home/default.conf /etc/nginx/sites-available/default
service nginx reload
else
echo "File does not exist, skipping cp."
fi
NOTE: $query_string can be used as well. See the official documentation here.
Our custom default.conf should look like the below:
server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /index.php?$args;
}
........
.....
...all the other default directives that were in this file originally...
}
Use an FTP client to upload both your startup.sh script and your custom default.sh to the /home directory for your PHP App Service.
Next, under ‘Configuration’ in the portal target /home/startup.sh (or whatever the startup script file name is).
Laravel App
Lastly, restart the App Service. This should now be using our custom startup script. Use LogStream or the Diagnose and Solve -> Application Logs detector, or other methods, to see the stdout from the script.

symfony + nginx + Plesk 12 - url rewriting not working fine

I have a symfony project with a lot of requests and users, so I decided to use nginx + php-fpm to get a bit more performance.
But my client wants to have plesk for server administration. So, I installed everything whats required (nginx, fpm, apache) and created the host instance in plesk. Now, the start page of the website works fine - but some child pages gives me a 404 error code directly from nginx, other child pages works.
All urls are rewritten (symfony default). I only renamed the symfony default index file of the web folder app.php to index.php.
My additional configuration in plesk is: nothing
edit: I use nginx 1.9.4 (delivered with ubuntu or plesk) and symfony 2.8
Try to add a following lines in "Apache & Nginx settings" > "Additional nginx directives" to your domain in Plesk:
if (!-f $request_filename) {
rewrite ^/(.*)$ /index.php last;
}

Categories