NOTE: Manually modifying the Nginx configuration will require adjustments to your server's permissions. Before you can do this, you will need to open a ticket so that we can adjust your permissions.
Create Nginx Site Configuration
In this example, the domain name is example.com. You will need to modify the commands to match the domain name you plan to use.
Nginx Site Configuration File
Copy the Nginx template to the Nginx sites-enabled directory as the new domain name:
cp /etc/nginx/sites-available/default-m2.conf /etc/nginx/sites-enabled/example.com
Update the template with the new domain name.
The sed command will replace the placeholder PLACER with the new domain name example.com:
sed 's/PLACER/example.com/g' -i /etc/nginx/sites-enabled/example.com
Remove the default server directive from the configuration file.
The sed command will remove the default_server directive from the configuration file and replace it with an empty string.
sed 's/ default_server//g' -i /etc/nginx/sites-enabled/example.com
Selecting PHP-FPM Version
Available versions of PHP-FPM can be listed using the command:
ls /etc/nginx/conf.d/nginx.conf.jetrails-*
/etc/nginx/conf.d/nginx.conf.jetrails-74 /etc/nginx/conf.d/nginx.conf.jetrails-81
For PHP 8.1 use 81, for 7.4 use 74.
sed 's/VERSION/82/g' -i /etc/nginx/sites-enabled/example.com
Create the file structure that Nginx expects. If these directories do not exist, Nginx will fail to start correctly.
mkdir -p /home/jetrails/example.com/html /home/jetrails/example.com/conf/ssl /home/jetrails/example.com/logs
SSL/TLS Configuration
Providing an SSL/TLS Certificate
An existing SSL certificate can be uploaded to /home/jetrails/example.com/conf/ssl/example.com.crt and the private key as /home/jetrails/example.com/conf/ssl/example.com.key.
Generating a Self-Signed Certificate
A new self-signed SSL certificate for use with Cloudflare can be generated using the following command.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /home/jetrails/example.com/conf/ssl/example.com.key -out /home/jetrails/example.com/conf/ssl/example.com.crt
It will prompt for information; pressing enter will leave the information blank.
Restarting Nginx
Before restarting Nginx, the configuration must be tested to ensure the process can start successfully.
Once the directories and SSL certificate are in place, you can test nginx with the following:
nginx -t
Nginx will return a success message if the test is successful; otherwise, it will return an error message with the configuration error.
>$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Once the test is completed successfully, the Nginx configuration can be reloaded.
systemctl reload nginx.service
Adding a Magento Multi-Store Configuration
In this example, the domain name for the additional Magento store configuration is 2ndshop.example.com. You will need to modify the commands with the domain name you plan to use.
Nginx Host Configuration
Copy the existing nginx entry for the new domain:
cp /etc/nginx/sites-enabled/example.com /etc/nginx/sites-enabled/2ndshop.example.com
Modify the new config to change the following lines:
server_name .example.com;
to
server_name .2ndshop.example.com;
and the access_log and error_log lines from
access_log /home/jetrails/jetrails.cloud/logs/example.com-ssl-access_log;
error_log /home/jetrails/jetrails.cloud/logs/example.com-ssl-error_log;
to
access_log /home/jetrails/jetrails.cloud/logs/2ndshop.example.com-ssl-access_log;
error_log /home/jetrails/jetrails.cloud/logs/2ndshop.example.com-ssl-error_log;
Nginx Variable Configuration
Update the Nginx variables to use the multi-store values in /etc/nginx/conf.d/global-map.conf using the store code and store type from Magento.
map $http_host $MAGE_RUN_CODE {
hostnames;
.example.com default;
}
map $http_host $MAGE_RUN_TYPE {
hostnames;
.example.com website;
}
Add the following to the file (You will need to substitute the domain name you have just added and the store code that you set up in your Magento backend):
map $http_host $MAGE_RUN_CODE {
hostnames;
.example.com default;
2ndshop.example.com 2ndshop;
}
map $http_host $MAGE_RUN_TYPE {
hostnames;
.example.com website;
2ndshop.example.com store;
}
Restarting Nginx
Before restarting Nginx, the configuration must be tested to ensure the process can start successfully.
nginx -t
Nginx will return a success message if the test is successful; otherwise, it will return an error message with the configuration error.
>$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Once the test is completed successfully, the Nginx configuration can be reloaded.
systemctl reload nginx.service
Comments
0 comments
Article is closed for comments.