Shopware with Caddy

Hello,
I am looking for a web server and wanted to try caddy now on my server. As far as everything works. Have only problems to run Shopware. Backend seems to work everything. Frontend comes 404 Not Found
Has anyone ever run shopware with Caddy?
Here my Caddy Configuration and Nginx Configuration, maybe someone has an idea.

CADDY

domain {
	root /data/www/shopware
    	gzip
    	log access.log
	errors error.log
	fastcgi / unix:/run/php/php7.0-fpm.sock php
    status 404 {
        /autoload.php
        /composer.json
        /composer.lock
        /composer.phar
        /config.php
        /files/documents/
        /var/
        /media/temp/
        /README.md
        /recovery/
        /.
    }
    rewrite /recovery/install/ {
        to /recovery/install/index.php
    }
    rewrite /recovery/update/ {
        to /recovery/update/index.php
    }    
    rewrite / {
        to {path} {path}/ /shopware.php
    }
}

NGINX is a little bit more

server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;
    	## Server certificate and key.
    	ssl_certificate      /etc/letsencrypt/live/...../fullchain.pem;
    	ssl_certificate_key  /etc/letsencrypt/live/...../privkey.pem;
	ssl_session_cache shared:SSL:20m;
	ssl_session_timeout 180m;
    	ssl_prefer_server_ciphers On;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    	ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
  	server_name ...........;
    	root /data/www/shopware;
    	index index.php index.html index.htm;
	location = /favicon.ico {
    		log_not_found off;
    		access_log off;
	}
	## Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
	location ~ /\. {
    		deny all;
    		access_log off;
    		log_not_found off;
	}
	## Deny all attems to access possible configuration files
	location ~ \.(tpl|yml|ini|log)$ {
    		deny all;
	}
	## Deny access to media upload folder
	location ^~ /media/temp/ {
    		deny all;
	}
	# Shopware caches and logs
	location ^~ /var/ {
    		deny all;
	}
	# Deny access to root files
	location ~ (autoload\.php|composer\.(json|lock|phar)|CONTRIBUTING\.md|eula.*\.txt|license\.txt|README\.md|UPGRADE\.md)$ {
    		return 404;
	}
	location ^~ /files/documents/ {
    		deny all;
	}
	## Fallback for old media paths
	location ^~ /media/ {
    		try_files $uri /shopware.php?controller=Media&action=fallback;
	}
	# Block direct access to ESDs, but allow the follwing download options:
	#  * 'PHP' (slow)
	#  * 'X-Accel' (optimized)
	# Also see http://wiki.shopware.com/ESD_detail_1116.html#Ab_Shopware_4.2.2
	location ^~ /files/552211cce724117c3178e3d22bec532ec/ {
    		internal;
	}
	# Shopware install / update
	location /recovery/install {
    		index index.php;
    		try_files $uri /recovery/install/index.php$is_args$args;
	}
	location /recovery/update/ {
       	        location /recovery/update/assets {
		}
		if (!-e $request_filename){
			rewrite . /recovery/update/index.php last;
		}
	}
	location / {
    		location ~* "^/themes/Frontend/Responsive/frontend/_public/vendors/fonts/open-sans-fontface/(?:.+)\.(?:ttf|eot|svg|woff)$" {
        		expires max;
        		add_header Cache-Control "public";
        		access_log off;
        		log_not_found off;
    		}
    		location ~* "^/themes/Frontend/Responsive/frontend/_public/src/fonts/(?:.+)\.(?:ttf|eot|svg|woff)$" {
        		expires max;
        		add_header Cache-Control "public";
        		access_log off;
        		log_not_found off;
    		}
    		location ~* "^/web/cache/(?:[0-9]{10})_(?:.+)\.(?:js|css)$" {
        		expires max;
        		add_header Cache-Control "public";
        		access_log off;
        		log_not_found off;
    		}
    		## All static files will be served directly.
    		location ~* ^.+\.(?:css|cur|js|jpe?g|gif|ico|png|html|xml)$ {
        		## Defining rewrite rules
        		rewrite files/documents/.* /engine last;
        		rewrite backend/media/(.*) /media/$1 last;
        		expires 1w;
        		add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        		access_log off;
        		# The directive enables or disables messages in error_log about files not found on disk.
        		log_not_found off;
        		tcp_nodelay off;
        		## Set the OS file cache.
        		open_file_cache max=3000 inactive=120s;
        		open_file_cache_valid 45s;
        		open_file_cache_min_uses 2;
        		open_file_cache_errors off;
        		## Fallback to shopware
        		## comment in if needed
        		#try_files $uri @shopware;
    		}
    		index shopware.php index.php;
    		try_files $uri $uri/ /shopware.php$is_args$args;
	}
	## XML Sitemap support.
	location = /sitemap.xml {
    		log_not_found off;
    		access_log off;
    		try_files $uri @shopware;
	}
	## XML SitemapMobile support.
	location = /sitemapMobile.xml {
    		log_not_found off;
    		access_log off;
    		try_files $uri @shopware;
	}
	## robots.txt support.
	location = /robots.txt {
    		log_not_found off;
    		access_log off;
	}
	location @shopware {
    		rewrite / /shopware.php;
	}
	# php-fpm configuration
	location ~ .php$ {
		root /data/www/shopware;
		try_files $uri =404;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
		fastcgi_read_timeout 180;
	}
}

Thank you for your help!
Frank

Iā€™m unfamiliar with Shopware, how do you access the backend?

With the address domain.com/backend
The error.log is empty.

What does the access.log say for the 404s?

This is the log part

> ... - [11/Jan/2017:10:54:49 +0000] "GET / HTTP/2.0" 404 38
> ... - [11/Jan/2017:10:54:49 +0000] "GET /shopware.php HTTP/2.0" 200 330
> ... - [11/Jan/2017:10:54:49 +0000] "GET /shopware.php HTTP/2.0" 200 164
> ... - [11/Jan/2017:10:54:50 +0000] "GET /shopware.php?_dc=1484132087398 HTTP/2.0" 200 74

This is an excerpt from my Caddyfile for a shopware demo shop with working frontend.

fastcgi / 127.0.0.1:9000 php {
  index shopware.php
  env PATH /bin
}

rewrite {
  to {path} {path}/ /shopware.php?{query}
}

Hope this helps!


self-promotion: My caddy-script has basic Shopware installation support :sweat_smile:

1 Like

Thank you! That works!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.