Tener Owncloud y WordPress en el mismo dominio con Nginx

Daré por hecho que ya tienes instalado WordPress y vas a instalar Owncloud (o viceversa) en tu servidor nginx.

Podrías pegar la configuración de ambos en el mismo archivo y tener algo incomprensible, o puedes organizarlo un poco.

Para una mejor organización y entendimiento te aconsejaría:

Crear en tu directorio /etc/nginx/sites-available tres archivos:

1. /etc/nginx/sites-available/midominio
En el incluyes la configuración básica de tu servidor virtual con los diferentes productos, algo como:

server {
 listen 80 default;
 server_name midominio.es www.midominio.es;
include sites-available/midominio-wordpress; 
}
server {
 listen 80;
 server_name minube.midominio.es;
 return 301 https://$server_name$request_uri; # forzar https
}
server {
 listen 443 ssl;
 server_name minube.midominio.es;
include sites-available/midominio-owncloud;
}

Yo he dejado el subdominio www para WordPress y creado otro subdominio para Owncloud, me parece más limpio que ponerlo en un subdirectorio. Aseguraos de dar de alta el subdominio CNAME en vuestro administrador del dominio.
Igualmente, fuerzo la redirección a https por razones obvias.

2. /etc/nginx/sites-availabe/midominio-wordpress
La configuración de WordPress. Os pego mi archivo de configuración. Lo he sacado de varias fuentes y me funciona muy bien:

Archivo de configuración de WordPress - pincha para mostrarlo

root /srv/www/www.midominio.es/public_html;

access_log /srv/www/www.midominio.es/logs/access.log;
error_log /srv/www/www.midominio.es/logs/error.log;
charset utf-8;
index index.html index.htm index.php;

location / {
        # This is cool because no php is touched for static content. 
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
	##
	# Fastcgi cache
	##
	set $skip_cache 1;
	if ($cache_uri != "null cache") {
		add_header X-Cache-Debug "$cache_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
		set $skip_cache 0;
	}
	fastcgi_cache_bypass $skip_cache;
	fastcgi_cache_key $scheme$host$request_uri$request_method;
	fastcgi_cache_valid any 8m;
	fastcgi_cache_bypass $http_pragma;
	fastcgi_cache_use_stale updating error timeout invalid_header http_500;

	##
	# WordPress PHP
	##
	try_files $uri /index.php;
	include fastcgi_params;
	fastcgi_read_timeout 300;
	fastcgi_pass unix:/var/run/php5-fpm.sock;
}

location = /favicon.ico {
	log_not_found off;
	access_log off;
}

location = /robots.txt {
	allow all;
	log_not_found off;
	access_log off;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
	
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { 
	log_not_found off; 
	expires max;
	add_header Pragma public;
	add_header Cache-Control "public";
}
# expires browser cache
location ~* \.(?:ico|css|js)$ {
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public";
}
#incluir bloqueos de exploits
## Block download agenta
if ($http_user_agent ~* LWP::Simple|wget|libwww-perl) {
	return 403;
}
## Block some nasty robots
if ($http_user_agent ~ (msnbot|Purebot|Baiduspider|Lipperhey|Mail.Ru|scrapbot) ) {
	return 403;
}
## Deny referal spam
if ( $http_referer ~* (jewelry|viagra|nude|girl|nudit|casino|poker|porn|sex|teen|babes) ) {
	return 403; 
}

set $cache_uri $request_uri;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
	set $cache_uri 'null cache';
}
if ($query_string != "") {
	set $cache_uri 'null cache';
}

# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
	set $cache_uri 'null cache';
}

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
	set $cache_uri 'null cache';
}

[plegar]

3. El archivo de configuración de Owncloud en /etc/nginx/sites-available/midominio-owncloud

Archivo de configuración de Owncloud - pincha para mostrarlo

ssl_certificate /etc/nginx/ssl/midominio.pem;
ssl_certificate_key /etc/nginx/ssl/midominio.key;

root /var/www/owncloud;

client_max_body_size 1000M; # set max upload size
fastcgi_buffers 64 4K;

rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) {
deny all;
}

location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;

rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

try_files $uri $uri/ index.php;
}

location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
}

# Optional: set long EXPIRES header on static assets
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
# Optional: Don’t log access to assets
access_log off;
}

[plegar]
Votar
[Total: 1 Media 5]

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *