# SNAP Installation change php, apache and nextcloud configs

**URL:** <https://help.nextcloud.com/t/snap-installation-change-php-apache-and-nextcloud-configs/32858>\
**Category:** 📦 Appliances (Docker, Snappy, VM, NCP, AIO)\
**Tags:** snap\
**Created:** [June 12, 2018, 1:15pm UTC](https://help.nextcloud.com/t/snap-installation-change-php-apache-and-nextcloud-configs/32858 "2018-06-12T13:15:30Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mactrent](https://help.nextcloud.com/letter_avatar/mactrent/32/5_5575768a8748004e209b776fc1b2916d.png) [@mactrent](https://help.nextcloud.com/u/mactrent)\
**Post date:** [August 18, 2020, 7:29pm UTC](https://help.nextcloud.com/t/snap-installation-change-php-apache-and-nextcloud-configs/32858/8 "2020-08-18T19:29:51Z")

</div>

@Bernd_Wechner  
Just in to be sure, have you followed PritishSehzpaul’s link to [make the snap writable](https://github.com/nextcloud/nextcloud-snap/wiki/Installing-the-snap-in-writable-mode)? I’d be interested to hear back if that didn’t do the trick.

> [@Bernd\_Wechner](#):
>
> The big question is why would Nextcloud redirect to itself in an endless loop when the request comes in via a reverse proxy.

A couple of easy mistakes that might cause this:

- If you have not set the ‘trusted\_proxies’ directive to match your reverse proxy IP, or if your reverse proxy does not send the ‘X-Forwarded-For’ header with the client’s IP. In these cases, Nextcloud can’t always tell it’s behind a reverse proxy - it will think it’s being accessed directly via its IP address all the time, so it will redirect you to nextcloud.mydomain.tld even if that’s where you’re already going.
- If you have set the ‘overwritecondaddr’ config directive, that could be the culprit. It’s included in the example in the reverse proxy docs you linked, but it’s optional. If you’re not sure what it does, you probably don’t need it.

There’s some additional [documentation](https://github.com/nextcloud/nextcloud-snap/wiki/Putting-the-snap-behind-a-reverse-proxy) specifically for using the snap behind a reverse proxy. It includes an nginx example you can work off of to make your apache reverse proxy config. You can also refer to mine below, if that helps.

* * *

I’m using LXC containers rather than Snaps in my setup, but it should still be helpful for reference. I’ve anonymized domains and IPs (nextcloud.mydomain.tld, nextcloud.lan, nextcloud\_direct\_ip, reverse\_proxy\_ip). If following the snap reverse proxy docs linked above, I guess all the IPs would be localhost (127.0.0.1), and you’d just change port numbers.

> **Nextcloud's config.php**
>
> ```auto
> $CONFIG = array (
> 'trusted_domains' => array (
> 0 => 'nextcloud.mydomain.tld',
> 1 => 'nextcloud.lan'
> ),
> 'trusted_proxies' => array (
> 0 => 'reverse_proxy_ip',
> ),
> 'overwrite.cli.url' => 'https://nextcloud.mydomain.tld/',
> 'overwriteprotocol' => 'https',
> 'overwritewebroot' => '/',
> 'htaccess.RewriteBase' => '/',
> [...]
> )
> 
> ```

> **Nextcloud container's Apache cfg**
>
> ```auto
> <VirtualHost *:80>
> ServerName nextcloud.mydomain.tld
> ServerAdmin webmaster@mydomain.tld
> 
> # Might be different in snap
> DocumentRoot /var/www/nextcloud
> 
> RemoteIPHeader X-Forwarded-For
> RemoteIPInternalProxy reverse_proxy_ip
> 
> <Directory /var/www/nextcloud/>
> Require all granted
> Options FollowSymlinks MultiViews
> AllowOverride All
> 
> <IfModule mod_dav.c>
> Dav off
> </IfModule>
> 
> # Might be unnecessary in the snap
> <IfModule mod_rewrite.c>
> RewriteEngine on
> RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
> RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
> RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
> RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
> RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
> </IfModule>
> 
> </Directory>
> 
> ErrorLog ${APACHE_LOG_DIR}/error.log
> CustomLog ${APACHE_LOG_DIR}/access.log combined
> </VirtualHost>
> 
> ```

> **Reverse proxy container's Apache cfg**
>
> ```auto
> <VirtualHost *:443>
> ServerName nextcloud.mydomain.tld
> 
> ProxyPreserveHost On
> 
> SSLProxyEngine on
> SSLProxyVerify none
> SSLProxyCheckPeerCN off
> SSLProxyCheckPeerName off
> SSLProxyCheckPeerExpire off
> 
> # Leave this part out until you're sure TLS is working properly
> #<IfModule mod_headers.c>
> # Header always set Strict-Transport-Security "max-age=15768000; preload"
> #</IfModule>
> 
> ProxyPass / http://nextcloud_direct_ip/
> ProxyPassReverse / http://nextcloud_direct_ip/
> 
> # TLS certs from letsencrypt/certbot, replace with your own paths
> Include /etc/letsencrypt/options-ssl-apache.conf
> SSLCertificateFile /etc/letsencrypt/live/nextcloud.mydomain.tld/fullchain.pem
> SSLCertificateKeyFile /etc/letsencrypt/live/nextcloud.mydomain.tld/privkey.pem
> 
> </VirtualHost>
> 
> ```

---

_[View the full topic](https://help.nextcloud.com/t/snap-installation-change-php-apache-and-nextcloud-configs/32858)._
