• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Plesk Custom Nginx Config for Magento 2

rudler-rocks

New Pleskian
Hello,
we are facing a problem where we can not find a suitable Solution.

We have magento2 installed with php fpm 7.0.16 and nginx.

No we have a config we need to insert. For now my thoughts were to change the nginx.conf in /var/www/vhosts/system/XXX/conf to:

server {
listen 80;
server_name bobicraft.de;
set $MAGE_ROOT /var/www/vhosts/XXX/httpdocs/;
set $MAGE_MODE default;
include /var/www/vhosts/XXX/httpdocs/nginx.conf.sample;
}

This works until we restart the service and the file is newly generated.
Is there a way to completely disable the auto generation for the nginx config file so we can just use our config. Any other solution wich fixes our problem would also be fine.

I already tried to insert the config from the nginx.conf.sample into the plesk backend for the domain but then we are facing duplicate entries for root and "/" and so on.

Thank you so much for any solution.
 

Attachments

  • nginx.conf.sample.txt
    4 KB · Views: 24
To me the file looks as if that is a fully featured configuration for a website. You need to remove all the parts that define a "server {...}" and only leave the parts inside of that bracket, not duplicating typical server definitions that are already part of the Plesk generated server configuration file. For example the upstream fast_cgi data is useless, because it defines a configuration that assumes that there is not yet an Nginx instance in place. The file you provide is simply an example of how Magento can be run on Nginx. In your case you will probably only need to add the location parts, but you must omit all the general server stuff from that example. That server stuff is handled by the Plesk configuration.
 
Thank you for your fast reply. Now i have the auto generated nginx.conf and i have added the location parts from the the magento sample configuration to the plesk backend under aditional nginx directives. Now there is still the problem that the configuration need the root $MAGE_ROOT/pub; and also the

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

but with both parts uncommented we get the error "root" directive is duplicate in ... and duplicate location "/" in ...

But i think both of the parts are needed to run magento properly. So what the solution for this parts. I have added the current config i have added under the nginx directives.

Regards
 

Attachments

  • nginx config.txt
    3.4 KB · Views: 74
The document root cannot be set in an include-configuration. It must be set from the "hosting settings" tab in Plesk. If your document root is not /httpdocs, but httpdocs/pub for instance, make that change in the "hosting settings". There is no need to set a document root from the include file.
 
Okay now i have changed the root in the hosting settings tab and just the duplicate location "/" is left. when this last problem is fixed everything should work as expected.
 
Are you sure that you have set your hosting to "Nginx only"? If you use Nginx as a reverse proxy, the above changes don't make sense and the location / is already defined by Plesk to define proxy settings to pass requests on to Apache. However, if hosting is set to Nginx only (uncheck the "proxy mode" checkbox in hosting settings), the "/" is no pre-defined location, hence the duplication location "/" is no longer duplicate.
 
It was set to proxy modus off now but to be honest i dont think what we want to achieve with magento 2 we can not reach in combination of magento,plesk,nginx and less knowlege. i thought it was much easier but for now i have to give up cause now the hole subscription is broken again. since i have installed everything 5,6,7 times i give up :(

thank you so much for your support, have a nice day.
 
You were so close with only one tiny little problem that remained - only the "/" location definition.
 
Just add (if your document root is already set to 'domain_name/pub'), to the 'Additional nginx directives' in Domain Setup

It will turn on 'Brotli' compression too.

I am still testing the setting, so far it works OK and we have a lot 3rd Party Extensions too!


Code:
index index.php;
autoindex off;
charset UTF-8;
error_page 404 403 = /errors/404.php;
#add_header "X-UA-Compatible" "IE=Edge";

# Deny access to sensitive files
location /.user.ini {
deny all;
}

# PHP entry point for setup application
location ~* ^/setup($|/) {
root /var/www/vhosts/xxxxx/httpdocs;
location ~ ^/setup/index.php {
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=10G \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ ^/setup/(?!pub/). {
deny all;
}

location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}

# PHP entry point for update application
location ~* ^/update($|/) {
root /var/www/vhosts/xxxxx/httpdocs;

location ~ ^/update/index.php {
fastcgi_split_path_info ^(/update/index.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}

# Deny everything but index.php
location ~ ^/update/(?!pub/). {
deny all;
}

location ~ ^/update/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}

location /var/www/vhosts/xxxxx/httpdocs {
try_files $uri $uri/ /index.php$is_args$args;
}

location /pub/ {
location ~ ^/pub/media/(downloadable|customer|import|custom_options|theme_customization/.*\.xml) {
deny all;
}
alias /var/www/vhosts/xxxxx/httpdocs/pub/;
add_header X-Frame-Options "SAMEORIGIN";
}

location /static/ {
# Uncomment the following line in production mode
# expires max;

# Remove signature of the static files that is used to overcome the browser cache
location ~ ^/static/version\d*/ {
rewrite ^/static/version\d*/(.*)$ /static/$1 last;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2|html|json|webmanifest)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;

if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;

if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/ {

## The following section allows to offload image resizing from Magento instance to the Nginx.
## Catalog image URL format should be set accordingly.
## See Web | Adobe Commerce 2.4 User Guide
# location ~* ^/media/catalog/.* {
#
# # Replace placeholders and uncomment the line below to serve product images from public S3
# # See examples of S3 authentication at GitHub - anomalizer/ngx_aws_auth: nginx module to proxy to authenticated AWS services
# # resolver 8.8.8.8;
# # proxy_pass https://<bucket-name>.<region-name>.amazonaws.com;
#
# set $width "-";
# set $height "-";
# if ($arg_width != '') {
# set $width $arg_width;
# }
# if ($arg_height != '') {
# set $height $arg_height;
# }
# image_filter resize $width $height;
# image_filter_jpeg_quality 90;
# }

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

location ~ ^/media/theme_customization/.*\.xml {
deny all;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ /get.php$is_args$args;
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
try_files $uri $uri/ /get.php$is_args$args;
}
add_header X-Frame-Options "SAMEORIGIN";
}

location /media/customer/ {
deny all;
}

location /media/downloadable/ {
deny all;
}

location /media/import/ {
deny all;
}

location /media/custom_options/ {
deny all;
}

location /errors/ {
location ~* \.xml$ {
deny all;
}
}
# PHP entry point for main application
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
try_files $uri =404;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=10G \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
brotli on;
brotli_comp_level 6;
brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml application/xhtml+xml text/javascript application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap;

gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml;
proxy_buffering on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;

# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.phtml$|\.htaccess$|\.git) {
deny all;
}
 
Back
Top