Jump to content

nginx configuration


Prestan0ob

Recommended Posts

Ανοίγω αυτό εδώ καθώς έχει συζητηθεί και σε άλλα ξένα topic παλαιότερα αλλά δεν υπάρχει κάτι πρόσφατο.
Επίσης υπάρχει αυτό εδώ αλλά πρέπει να είναι παλαιό καθώς λείπουν αρκετές απο τις ρυθμίσεις που αναφέρουν χρήστες σε άλλες σελίδες:
https://devdocs.prestashop.com/1.7/basics/installation/nginx/

Σε κάποιες εκδόσεις/θέματα prestashop υπάρχει πρόβλημα στην σελίδα προϊόντων όταν επιλέγεις κάποια ιδιότητα / συνδιασμό ή όταν επιλέγεις ποσότητα. Έχει να κάνει με το redirect και τις ρυθμίσεις του nginx.
π.χ εδώ:

Γενικότερα όμως υπάρχει κάποιο πρόσφατο άρθρο για τις καλύτερες δυνατές ρυθμίσεις nginx για το prestashop;

Link to comment
Share on other sites

Δεν γνωρίζω ακριβώς τι πρέπει να κοιτάξω. Πρέπει να προσθέσω οτιδήποτε υπάρχει μέσα στο htaccess στο nginx; Απο ότι θυμάμαι όταν έχεις nginx κάνει bypass το htaccess και πρέπει να κάνεις οτιδήποτε μέσα απο το nginx.conf. Σωστά; Αλλά ενώ έχω επιλέξει Nginx στον server διαβάζει το htaccess και κάνει σωστά τα redirects εκτός απο την σελίδα των προϊόντων που βγάζει το error που αναφέρω πιο πάνω. Επίσης δεν ξέρω σε σχέση με gzip και άλλα που έχουν να κάνουν με την ταχύτητα τι παίζει.

To htaccess είναι αυτό

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on


#Domain: mydomain.gr
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api(?:/(.*))?$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^mydomain.gr$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType font/woff2 .woff2
<IfModule mod_headers.c>
	<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
		Header set Access-Control-Allow-Origin "*"
	</FilesMatch>

    <FilesMatch "\.pdf$">
      Header set Content-Disposition "Attachment"
      Header set X-Content-Type-Options "nosniff"
    </FilesMatch>
</IfModule>

<Files composer.lock>
    # Apache 2.2
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>

    # Apache 2.4
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
</Files>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

και το nginx
 

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

server {
	listen 3.136.69.71:443 ssl http2;

	server_name mydomain.gr;
	server_name www.mydomain.gr;
	server_name ipv4.mydomain.gr;

	ssl_certificate             /usr/local/psa/var/certificates/scfbR0RZx;
	ssl_certificate_key         /usr/local/psa/var/certificates/scfbR0RZx;

	client_max_body_size 128m;

	# mailconfig
	location ~* ^/autodiscover/autodiscover\.xml$ {
		try_files $uri @mad;
	}
	location ~* ^(/\.well-known/autoconfig)?/mail/config\-v1\.1\.xml$ {
		try_files $uri @mad;
	}

	location  ~* ^/email\.mobileconfig$ {
		try_files $uri @mad;
	}

	location @mad {
		rewrite ^(.*)$ /mailconfig/ break;

		proxy_pass                          http://127.0.0.1:8880;
		proxy_set_header X-Host             $host;
		proxy_set_header X-Request-URI      $request_uri;
	}
	# mailconfig

	root "/var/www/vhosts/mydomain.gr/httpdocs";
	access_log "/var/www/vhosts/system/mydomain.gr/logs/proxy_access_ssl_log";
	error_log "/var/www/vhosts/system/mydomain.gr/logs/proxy_error_log";

	#extension letsencrypt begin
	location ^~ /.well-known/acme-challenge/ {
		root /var/www/vhosts/default/htdocs;

		types { }
		default_type text/plain;

		satisfy any;
		auth_basic off;
		allow all;

		location ~ ^/\.well-known/acme-challenge.*/\. {
			deny all;
		}
	}
	#extension letsencrypt end

	#extension sslit begin

	#OCSP Stapling
	ssl_stapling on;
	ssl_stapling_verify on;

	#extension sslit end

	error_page 400 "/error_docs/bad_request.html";
	error_page 401 "/error_docs/unauthorized.html";
	error_page 403 "/error_docs/forbidden.html";
	error_page 404 "/error_docs/not_found.html";
	error_page 500 "/error_docs/internal_server_error.html";
	error_page 405 "/error_docs/method_not_allowed.html";
	error_page 406 "/error_docs/not_acceptable.html";
	error_page 407 "/error_docs/proxy_authentication_required.html";
	error_page 412 "/error_docs/precondition_failed.html";
	error_page 414 "/error_docs/request_uri_too_long.html";
	error_page 415 "/error_docs/unsupported_media_type.html";
	error_page 501 "/error_docs/not_implemented.html";
	error_page 502 "/error_docs/bad_gateway.html";
	error_page 503 "/error_docs/maintenance.html";

	location ^~ /error_docs {
		root "/var/www/vhosts/mydomain.gr";
	}

	location / {
		proxy_pass https://3.136.69.71:7081;
		proxy_hide_header upgrade;
		proxy_set_header Host             $host;
		proxy_set_header X-Real-IP        $remote_addr;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_set_header X-Accel-Internal /internal-nginx-static-location;
		access_log off;

	}

	location /internal-nginx-static-location/ {
		alias /var/www/vhosts/mydomain.gr/httpdocs/;
		internal;
	}

	location ~ ^/(plesk-stat|awstats-icon|webstat|webstat-ssl|ftpstat|anon_ftpstat) {
		proxy_pass https://3.136.69.71:7081;
		proxy_hide_header upgrade;
		proxy_set_header Host             $host;
		proxy_set_header X-Real-IP        $remote_addr;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_set_header X-Accel-Internal /internal-nginx-static-location;
		access_log off;

	}

	location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
		alias /var/www/vhosts/mydomain.gr/web_users/$1/$2;
		fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
		try_files $uri $fastcgi_script_name =404;
		fastcgi_param PATH_INFO $fastcgi_path_info;
		fastcgi_pass "unix:/var/www/vhosts/system/mydomain.gr/php-fpm.sock";
		include /etc/nginx/fastcgi.conf;

	}

	location ~ ^/~(.+?)(/.*)?$ {
		proxy_pass https://3.136.69.71:7081;
		proxy_hide_header upgrade;
		proxy_set_header Host             $host;
		proxy_set_header X-Real-IP        $remote_addr;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_set_header X-Accel-Internal /internal-nginx-static-location;
		access_log off;

	}

	location ~ \.php(/.*)?$ {
		fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
		try_files $uri $fastcgi_script_name =404;
		fastcgi_param PATH_INFO $fastcgi_path_info;
		fastcgi_pass "unix:/var/www/vhosts/system/mydomain.gr/php-fpm.sock";
		include /etc/nginx/fastcgi.conf;

	}

	add_header X-Powered-By PleskLin;

	include "/var/www/vhosts/system/mydomain.gr/conf/vhost_nginx.conf";
}

server {
	listen 213.136.69.71:80;

	server_name mydomain.gr;
	server_name www.mydomain.gr;
	server_name ipv4.mydomain.gr;

	client_max_body_size 128m;

	# mailconfig
	location ~* ^/autodiscover/autodiscover\.xml$ {
		try_files $uri @mad;
	}
	location ~* ^(/\.well-known/autoconfig)?/mail/config\-v1\.1\.xml$ {
		try_files $uri @mad;
	}

	location  ~* ^/email\.mobileconfig$ {
		try_files $uri @mad;
	}

	location @mad {
		rewrite ^(.*)$ /mailconfig/ break;

		proxy_pass                          http://127.0.0.1:8880;
		proxy_set_header X-Host             $host;
		proxy_set_header X-Request-URI      $request_uri;
	}
	# mailconfig

	location / {
		return 301 https://$host$request_uri;
	}
}

 

Edited by Prestan0ob (see edit history)
Link to comment
Share on other sites

Στο nginx config που έστειλες δεν έχεις καθόλου τα rewrite.

Προφανώς τα έχεις per domain settings.

include "/var/www/vhosts/system/mydomain.gr/conf/vhost_nginx.conf";

Κάνε ένα cat το παραπάνω στο domain που έχεις θέμα.

Link to comment
Share on other sites

το παραπάνω που γράφεις vhost_nginx.conf είναι άδειο (με το βέλος). Αυτό που ανέβασα πιο πάνω είναι αυτό που είναι μέσα στο τετράγωνο. Είναι και τα 2 μέσα στον κατάλογο που αναφέρεις (per domain settings).


1572777023_.png.e671b6512d880910cfdae12c0fbbfe19.png

Link to comment
Share on other sites

3 hours ago, sanctusmob said:

Αυτό που μου δείχνεις είναι πως τρέχει php…

Οκ κατάλαβα. Και χρησιμοποιεί την nginx για reserve. Οπότε γι'αυτό διαβάζει το htaccess. Αλλά γιατί δεν λειτουργεί σωστά το redirect? Αυτό που αναφέρω δηλαδή στο κάτω μέρος εδώ:

Μήπως πρέπει να προσθέσω κάτι στο vhost_nginx.conf ?

Link to comment
Share on other sites

@Prestan0ob Δεν είναι κάτι που μπορεί να σου απαντήση κάποιος αν δεν μπει και να δει ακριβός το πρόβλημα και τι έχεις ώστε να προτείνη μία λύση.

Πάνε Advanced Parameters \ Information και πες με τι έχεις στο server information.

Link to comment
Share on other sites

7 hours ago, sanctusmob said:

@Prestan0ob Δεν είναι κάτι που μπορεί να σου απαντήση κάποιος αν δεν μπει και να δει ακριβός το πρόβλημα και τι έχεις ώστε να προτείνη μία λύση.

Πάνε Advanced Parameters \ Information και πες με τι έχεις στο server information.

Server information Linux #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64

Server software version: nginx/1.20.1

PHP version: 7.3.32

Memory limit: 128M

Max execution time: 30

Upload Max File size: 8M

Για να παίζει με nginx μήπως πρέπει να απενεργοιήσω αυτή την ρύθμιση στο plesk?
 

εικόνα.png

Edited by Prestan0ob (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...