Código fuente wiki de Instalacion (docker)
Última modificación por dFa el 2025/02/24 10:01
Mostrar los últimos autores
author | version | line-number | content |
---|---|---|---|
1 | (% class="jumbotron" %) | ||
2 | ((( | ||
3 | (% class="container" %) | ||
4 | ((( | ||
5 | = NEXTCLOUD = | ||
6 | |||
7 | Instalación de nextcloud mediante docker | ||
8 | ))) | ||
9 | ))) | ||
10 | |||
11 | ---- | ||
12 | |||
13 | |||
14 | {{toc/}} | ||
15 | |||
16 | (% class="row" %) | ||
17 | ((( | ||
18 | (% class="col-xs-12 col-sm-8" %) | ||
19 | ((( | ||
20 | ---- | ||
21 | |||
22 | = INICIO = | ||
23 | |||
24 | == Instalación == | ||
25 | |||
26 | La instalación consta de 4 servicios: | ||
27 | |||
28 | * db: Base de datos mariadb | ||
29 | * redis: Base de datos de memoria caché redis | ||
30 | * app: Aplicativo nextcloud | ||
31 | * web: Servidor web nginx, se encarga de redireccionar las peticiones hacia el aplicativo (app) | ||
32 | |||
33 | El primer paso es generar nuestro docker-compose: | ||
34 | |||
35 | {{code language="yaml"}} | ||
36 | services: | ||
37 | db: | ||
38 | image: mariadb:10.11 | ||
39 | container_name: nextcloud-db | ||
40 | restart: unless-stopped | ||
41 | command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW | ||
42 | volumes: | ||
43 | - database:/var/lib/mysql | ||
44 | environment: | ||
45 | MYSQL_ROOT_PASSWORD: Ko5b0sq977j1saaCQ3SD55 | ||
46 | MYSQL_DATABASE: nextcloud | ||
47 | MYSQL_USER: nextcloud | ||
48 | MYSQL_PASSWORD: Ko5b0sq977j1saaCQ3SD55 | ||
49 | |||
50 | redis: | ||
51 | image: redis:alpine | ||
52 | container_name: nextcloud-redis | ||
53 | restart: unless-stopped | ||
54 | volumes: | ||
55 | - redis:/data | ||
56 | |||
57 | app: | ||
58 | image: nextcloud:fpm | ||
59 | container_name: nextcloud-app | ||
60 | restart: unless-stopped | ||
61 | ports: | ||
62 | - 9000:9000 | ||
63 | depends_on: | ||
64 | - db | ||
65 | - redis | ||
66 | volumes: | ||
67 | - data:/var/www/html | ||
68 | - user:/var/nextcloud/data | ||
69 | - /datos/dFa:/mnt | ||
70 | environment: | ||
71 | MYSQL_HOST: db | ||
72 | MYSQL_DATABASE: nextcloud | ||
73 | MYSQL_USER: nextcloud | ||
74 | MYSQL_PASSWORD: Ko5b0sq977j1saaCQ3SD55 | ||
75 | REDIS_HOST: redis | ||
76 | PHP_UPLOAD_LIMIT: 0 | ||
77 | NEXTCLOUD_DATA_DIR: /var/nextcloud/data | ||
78 | command: > | ||
79 | sh -c "chown -R www-data:www-data /var/nextcloud && | ||
80 | chmod -R 770 /var/nextcloud && | ||
81 | exec /entrypoint.sh php-fpm" | ||
82 | |||
83 | web: | ||
84 | image: nginx | ||
85 | container_name: nextcloud-web | ||
86 | restart: always | ||
87 | ports: | ||
88 | - 8080:80 | ||
89 | depends_on: | ||
90 | - app | ||
91 | volumes: | ||
92 | - nginx_conf:/etc/nginx | ||
93 | - data:/var/www/html | ||
94 | volumes_from: | ||
95 | - app | ||
96 | |||
97 | volumes: | ||
98 | data: | ||
99 | driver: local | ||
100 | database: | ||
101 | driver: local | ||
102 | redis: | ||
103 | driver: local | ||
104 | nginx_conf: | ||
105 | driver: local | ||
106 | user: | ||
107 | driver: local | ||
108 | {{/code}} | ||
109 | |||
110 | Los volúmenes se han configurado por las siguientes razones: | ||
111 | |||
112 | * database: Ficheros de la base de datos mysql | ||
113 | * redis: Ficheros de la base de datos de memoria caché | ||
114 | * data: Ficheros del aplicativo nextcloud (es necesario que lo usen tanto el contenedor app como el contenedor web) | ||
115 | * user: Ficheros de los perfiles de usuarios creados para nextcloud | ||
116 | * nginx_conf: Fichero nginx.conf | ||
117 | |||
118 | Además, en este caso, se ha realizado un bind de nuestro disco /datos para que sea utilizado como punto de montaje en nextcloud. Dado que es un contenedor, es necesario mapearlo para que la interfaz web tenga acceso al recurso de alguna manera. | ||
119 | |||
120 | {{code}} | ||
121 | - /datos/dFa:/mnt | ||
122 | {{/code}} | ||
123 | |||
124 | También se añade la adición de permisos al directorio /var/nextcloud durante la generación del contenedor, dado que el directorio se crea durante la creación del volumen "user". | ||
125 | |||
126 | {{code}} | ||
127 | command: > | ||
128 | sh -c "chown -R www-data:www-data /var/nextcloud && | ||
129 | chmod -R 770 /var/nextcloud && | ||
130 | exec /entrypoint.sh php-fpm" | ||
131 | {{/code}} | ||
132 | |||
133 | Desplegamos los contenedores: | ||
134 | |||
135 | [[image:1740216653242-590.png]] | ||
136 | |||
137 | Y vemos que se han creado los volumenes correctamente: | ||
138 | |||
139 | [[image:1740216641833-376.png]] | ||
140 | |||
141 | == Configuración == | ||
142 | |||
143 | Con los volumenes creados, todavía nextcloud no es accesible, dado que debemos configurar tanto el config.php como como el nginx.conf. | ||
144 | |||
145 | === nginx.conf === | ||
146 | |||
147 | El fichero nginx.conf se encuentra en el volumen nextcloud_nginx_conf. Realizamos previamente un backup y reemplazamos por el siguiente: | ||
148 | |||
149 | {{code language="yaml"}} | ||
150 | worker_processes auto; | ||
151 | |||
152 | error_log /var/log/nginx/error.log warn; | ||
153 | pid /var/run/nginx.pid; | ||
154 | |||
155 | events { | ||
156 | worker_connections 1024; | ||
157 | } | ||
158 | |||
159 | http { | ||
160 | include mime.types; | ||
161 | default_type application/octet-stream; | ||
162 | types { | ||
163 | text/javascript mjs; | ||
164 | application/wasm wasm; | ||
165 | } | ||
166 | |||
167 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
168 | '$status $body_bytes_sent "$http_referer" ' | ||
169 | '"$http_user_agent" "$http_x_forwarded_for"'; | ||
170 | |||
171 | access_log /var/log/nginx/access.log main; | ||
172 | |||
173 | sendfile on; | ||
174 | keepalive_timeout 65; | ||
175 | |||
176 | # Define asset_immutable variable properly | ||
177 | map $arg_v $asset_immutable { | ||
178 | default ""; | ||
179 | "" ", immutable"; | ||
180 | } | ||
181 | |||
182 | upstream php-handler { | ||
183 | server app:9000; | ||
184 | } | ||
185 | |||
186 | server { | ||
187 | listen 80; | ||
188 | |||
189 | client_max_body_size 512M; | ||
190 | client_body_timeout 300s; | ||
191 | fastcgi_buffers 64 4K; | ||
192 | |||
193 | client_body_buffer_size 512k; | ||
194 | |||
195 | gzip on; | ||
196 | gzip_vary on; | ||
197 | gzip_comp_level 4; | ||
198 | gzip_min_length 256; | ||
199 | gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; | ||
200 | gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; | ||
201 | |||
202 | add_header Referrer-Policy "no-referrer" always; | ||
203 | add_header X-Content-Type-Options "nosniff" always; | ||
204 | add_header X-Frame-Options "SAMEORIGIN" always; | ||
205 | add_header X-Permitted-Cross-Domain-Policies "none" always; | ||
206 | add_header X-Robots-Tag "noindex, nofollow" always; | ||
207 | add_header X-XSS-Protection "1; mode=block" always; | ||
208 | |||
209 | fastcgi_hide_header X-Powered-By; | ||
210 | |||
211 | root /var/www/html; | ||
212 | |||
213 | index index.php index.html /index.php$request_uri; | ||
214 | |||
215 | location = / { | ||
216 | if ( $http_user_agent ~ ^DavClnt ) { | ||
217 | return 302 /remote.php/webdav/$is_args$args; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | location = /robots.txt { | ||
222 | allow all; | ||
223 | log_not_found off; | ||
224 | access_log off; | ||
225 | } | ||
226 | |||
227 | location ^~ /.well-known { | ||
228 | location = /.well-known/carddav { return 301 /remote.php/dav/; } | ||
229 | location = /.well-known/caldav { return 301 /remote.php/dav/; } | ||
230 | location /.well-known/acme-challenge { try_files $uri $uri/ =404; } | ||
231 | location /.well-known/pki-validation { try_files $uri $uri/ =404; } | ||
232 | return 301 /index.php$request_uri; | ||
233 | } | ||
234 | |||
235 | location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; } | ||
236 | location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; } | ||
237 | |||
238 | location ~ \.php(?:$|/) { | ||
239 | rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode(_arm64)?\/proxy) /index.php$request_uri; | ||
240 | |||
241 | fastcgi_split_path_info ^(.+?\.php)(/.*)$; | ||
242 | set $path_info $fastcgi_path_info; | ||
243 | |||
244 | try_files $fastcgi_script_name =404; | ||
245 | |||
246 | include fastcgi_params; | ||
247 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
248 | fastcgi_param PATH_INFO $path_info; | ||
249 | fastcgi_param HTTPS on; | ||
250 | |||
251 | fastcgi_param modHeadersAvailable true; | ||
252 | fastcgi_param front_controller_active true; | ||
253 | fastcgi_pass php-handler; | ||
254 | |||
255 | fastcgi_intercept_errors on; | ||
256 | fastcgi_request_buffering off; | ||
257 | |||
258 | fastcgi_max_temp_file_size 0; | ||
259 | } | ||
260 | |||
261 | location ~ \.(?:css|js|mjs|svg|gif|ico|jpg|png|webp|wasm|tflite|map|ogg|flac)$ { | ||
262 | try_files $uri /index.php$request_uri; | ||
263 | add_header Cache-Control "public, max-age=15778463$asset_immutable"; | ||
264 | access_log off; | ||
265 | } | ||
266 | |||
267 | location ~ \.wasm$ { | ||
268 | default_type application/wasm; | ||
269 | } | ||
270 | |||
271 | location /remote { | ||
272 | return 301 /remote.php$request_uri; | ||
273 | } | ||
274 | |||
275 | location / { | ||
276 | try_files $uri $uri/ /index.php$request_uri; | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | {{/code}} | ||
281 | |||
282 | Reiniciamos los contenedores para que apliquen todos los cambios y comprobamos si funciona correctamente accediendo a través del puerto expuesto, en este caso el 8080: | ||
283 | |||
284 | * [[http:~~/~~/ipservidor:8080>>http://ipservidor:8080]] | ||
285 | |||
286 | [[image:1740220925385-402.png]] | ||
287 | |||
288 | Indicamos un usuario y contraseña y comenzará la instalación. | ||
289 | |||
290 | === config.php === | ||
291 | |||
292 | Una vez realizada la instalación, nos redireccionará mediante https lo cual dará el siguiente error: | ||
293 | |||
294 | [[image:1740242599208-350.png]] | ||
295 | |||
296 | Procedemos a modificar el fichero config.php que se encuentra en el volumen app dentro del directorio config con la siguiente configuración, teniendo en cuenta de no reemplazar los siguiente valores: | ||
297 | |||
298 | {{code language="php"}} | ||
299 | 'passwordsalt' => 'bFuPjx3NMpliQCtY729Uob2SRp19xe', | ||
300 | 'secret' => 'eFMG77LAdbjw6oPSJM7hL/IDPBnP3qDxE7xlX6/uPMOvQ/kG' | ||
301 | 'dbpassword' => 'Ko5b0sq977j1saaCQ3SD55' | ||
302 | {{/code}} | ||
303 | |||
304 | config.php: | ||
305 | |||
306 | {{code language="php"}} | ||
307 | <?php | ||
308 | $CONFIG = array ( | ||
309 | 'memcache.local' => '\\OC\\Memcache\\APCu', | ||
310 | 'apps_paths' => | ||
311 | array ( | ||
312 | 0 => | ||
313 | array ( | ||
314 | 'path' => '/var/www/html/apps', | ||
315 | 'url' => '/apps', | ||
316 | 'writable' => false, | ||
317 | ), | ||
318 | 1 => | ||
319 | array ( | ||
320 | 'path' => '/var/www/html/custom_apps', | ||
321 | 'url' => '/custom_apps', | ||
322 | 'writable' => true, | ||
323 | ), | ||
324 | ), | ||
325 | 'memcache.distributed' => '\\OC\\Memcache\\Redis', | ||
326 | 'memcache.locking' => '\\OC\\Memcache\\Redis', | ||
327 | 'redis' => | ||
328 | array ( | ||
329 | 'host' => 'redis', | ||
330 | 'password' => '', | ||
331 | 'port' => 6379, | ||
332 | ), | ||
333 | 'upgrade.disable-web' => true, | ||
334 | 'instanceid' => 'ocxuwrcpcats', | ||
335 | 'passwordsalt' => 'bFuPjx3NMpliQCtY729Uob2SRp19xe', | ||
336 | 'secret' => 'eFMG77LAdbjw6oPSJM7hL/IDPBnP3qDxE7xlX6/uPMOvQ/kG', | ||
337 | 'trusted_domains' => | ||
338 | array ( | ||
339 | 0 => '10.100.200.35:8080', | ||
340 | 1 => 'dfacloud.ddns.net', | ||
341 | |||
342 | ), | ||
343 | 'datadirectory' => '/var/nextcloud/data', | ||
344 | 'dbtype' => 'mysql', | ||
345 | 'version' => '30.0.6.2', | ||
346 | 'overwrite.cli.url' => 'https://dfacloud.ddns.net', | ||
347 | 'overwritehost' => '10.100.200.35:8080', | ||
348 | 'overwriteprotocol' => 'http', | ||
349 | 'dbname' => 'nextcloud', | ||
350 | 'dbhost' => 'db', | ||
351 | 'dbport' => '', | ||
352 | 'dbtableprefix' => 'oc_', | ||
353 | 'mysql.utf8mb4' => true, | ||
354 | 'dbuser' => 'nextcloud', | ||
355 | 'dbpassword' => 'Ko5b0sq977j1saaCQ3SD55', | ||
356 | 'installed' => true, | ||
357 | ); | ||
358 | {{/code}} | ||
359 | |||
360 | En este fichero php tendremos que tener en cuenta modificar los valores nuestra dirección ip:puerto y nuestra dns en consecuencia. | ||
361 | |||
362 | Tambien debemos tener en cuenta la directiva: | ||
363 | |||
364 | * 'datadirectory' => '/var/nextcloud/data', | ||
365 | |||
366 | Dado que indica el directorio de datos dentro del contenedor. | ||
367 | |||
368 | Así como la directivas: | ||
369 | |||
370 | * overwrite.cli.url' => 'https:~/~/dfacloud.ddns.net' | ||
371 | * 'overwritehost' => '10.100.200.35:8080' | ||
372 | * 'overwriteprotocol' => 'http' | ||
373 | |||
374 | Estas directivas garantizarán que podremos acceder mediante http de manera local y mediante https de manera externa. | ||
375 | |||
376 | (% class="wikigeneratedid" %) | ||
377 | Tras esto ya podremos acceder a nextcloud correctamente. | ||
378 | |||
379 | === Permisos === | ||
380 | |||
381 | Es importante tener en cuenta los permisos de los directorios, sobre todo los directorios de datos y perfiles de usuarios. | ||
382 | |||
383 | En nuestro caso hemos montado el perfil de usuario en un directorio distinto dado que es una recomendación de seguridad de nextcloud, y además hemos expuesto nuestro disco /datos montando en el host anfitrión al contenedor, por lo que es posible que tengamos que revisar los permisos. | ||
384 | |||
385 | El usuario y grupo desde el host anfitrión en nuestro caso son: | ||
386 | |||
387 | * user: 33 (www-data) | ||
388 | * group: tape (www-data) | ||
389 | |||
390 | Y deben contener permisos 770 | ||
391 | |||
392 | Hemos ajustado el compose para que se adapten estos permisos de forma automática, no obstante es importante revisarles si nextcloud indica algún problema de permisos. | ||
393 | |||
394 | = OTROS = | ||
395 | |||
396 | == Compartir recurso que se usa en docker por smb == | ||
397 | |||
398 | Si vamos a compartir un directorio de datos usado por docker tambien a través de smb, es importante tener en cuenta los permisos. | ||
399 | |||
400 | Para ello añadiremos nuestro usuario de smb al grupo tape e indicaremos en el recurso smb como usuario valido dicho grupo. | ||
401 | |||
402 | Para añadir el usuario al grupo tape: | ||
403 | |||
404 | {{code language="bash"}} | ||
405 | usermod -a -G tape usuario | ||
406 | {{/code}} | ||
407 | |||
408 | Para configurar el grupo en smb: | ||
409 | |||
410 | {{code language="bash"}} | ||
411 | [datos] | ||
412 | path = /datos/dFa | ||
413 | browsable = yes | ||
414 | writable = yes | ||
415 | valid users = @tape | ||
416 | #valid users = dFa | ||
417 | read only = no | ||
418 | force create mode = 0777 | ||
419 | force directory mode = 0777 | ||
420 | guest ok = no | ||
421 | {{/code}} | ||
422 | |||
423 | De esta manera tanto docker como el usuario de smb que hemos añadido al grupo tape tendrá permisos sobre el recurso. | ||
424 | |||
425 | También para evitar problemas, es importante asignar ACL's para que el recurso siempre tenga los mismos permisos cuando se añade un nuevo fichero y además aseguramos que el contenido ya existente se encuentra en un estado correcto en cuanto a los mismos: | ||
426 | |||
427 | {{code language="bash"}} | ||
428 | setfacl -R -m g:tape:rwx /datos/ | ||
429 | setfacl -R -d -m g:tape:rwx /datos/ | ||
430 | {{/code}} | ||
431 | |||
432 | |||
433 | |||
434 | |||
435 | ))) | ||
436 | ))) |