Ich habe eine VPS-Ghost-Installation, die auf Nginx ausgeführt wird. Ich habe ein SSL-Zertifikat dafür erstellt und alles funktioniert gut, abgesehen davon, dass alle http://subdomain.example.com
immer zurück zu meinem Haupt https://example.com
bei Verwendung von HTTP umleiten.nginx Konfigurieren von Subdomains auf https
Allerdings, wenn ich https://subdomain.example.com
besuchen, wird nicht zurück zu example.com
umgeleitet. Ich möchte sicherstellen, dass, wenn meine Benutzer *.example.com
besuchen, sie nicht zurück zur Hauptdomäne umleiten, unabhängig davon, ob sie HTTP/S verwenden.
Der Grund dafür ist, weil ich versuche, ownCloud auf einer eigenen Subdomain einzurichten und kann nur auf es derzeit von example.com/cloud
zugreifen.
Ich habe viele Stunden damit verbracht, die Conf-Dateien auf nginx zu konfigurieren, bitte helfen Sie mir!
Hier sind meine zwei nginx Konfigurationsdateien -
Für die Hauptdomain:
server {
listen 80;
server_name notepad.li;
ssl_certificate /etc/letsencrypt/live/notepad.li/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/notepad.li/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name notepad.li;
root /var/www/ghost/;
ssl_certificate /etc/letsencrypt/live/notepad.li/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/notepad.li/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
client_max_body_size 200M;
location ~ /.well-known {
allow all;
}
location/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
location /robots.txt {
alias /var/www/notepad/robots.txt;
}
rewrite ^/cloud$ /cloud/ redirect;
rewrite ^/cloud/$ /cloud/index.php;
rewrite ^/cloud/(contacts|calendar|files)$ /cloud/index.php/apps/$1/ redirect;
rewrite ^(/cloud/core/doc/[^\/]+/)$ $1/index.html;
location /cloud/ {
alias /var/www/owncloud/;
location ~ ^/cloud/(build|tests|config|lib|3rdparty|templates|data|README)/ {
deny all;
}
location ~ ^/cloud/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
}
location ~ ^(/cloud)((?:/ocs)?/[^/]+\.php)(/.*)?$ {
# note: ~ has precendence over a regular location block
# Accept URLs like:
# /cloud/index.php/apps/files/
# /cloud/index.php/apps/files/ajax/scan.php (it's really index.php; see 6fdef379adfdeac86cc2220209bdf4eb9562268d)
# /cloud/ocs/v1.php/apps/files_sharing/api/v1 (see #240)
# /cloud/remote.php/webdav/yourfilehere...
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/owncloud/$2;
fastcgi_param SCRIPT_NAME $1$2;
fastcgi_param PATH_INFO $3;
fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
fastcgi_param MOD_X_ACCEL_REDIRECT_PREFIX /owncloud-xaccel;
fastcgi_read_timeout 630;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
client_max_body_size 1G;
fastcgi_buffers 64 4K;
}
location ^~ /owncloud-xaccel/ {
# This directory is for MOD_X_ACCEL_REDIRECT_ENABLED. ownCloud sends the full file
# path on disk as a subdirectory under this virtual path.
# We must only allow 'internal' redirects within nginx so that the filesystem
# is not exposed to the world.
internal;
alias /;
}
location ~ ^/((caldav|carddav|webdav).*)$ {
# Z-Push doesn't like getting a redirect, and a plain rewrite didn't work either.
# Properly proxying like this seems to work fine.
proxy_pass https://127.0.0.1/cloud/remote.php/$1;
}
rewrite ^/.well-known/host-meta /cloud/public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /cloud/public.php?service=host-meta-json last;
rewrite ^/.well-known/carddav /cloud/remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /cloud/remote.php/caldav/ redirect;
}
Für die Sub-Domain:
upstream php-handler {
server unix:/run/php/php7.0-fpm.sock;
}
server {
listen 80;
server_name box.notepad.li;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name box.notepad.li;
ssl_certificate /etc/letsencrypt/live/box.notepad.li/fullchain.crt;
ssl_certificate_key /etc/letsencrypt/live/box.notepad.li/privkey.key;
# Add headers to serve security related headers
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Path to the root of your installation
root /var/www/owncloud/;
# set max upload size
client_max_body_size 10G;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
rewrite ^/.well-known/carddav /remote.php/dav/ permanent;
rewrite ^/.well-known/caldav /remote.php/dav/ permanent;
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location/{
rewrite ^/remote/(.*) /remote.php last;
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ =404;
}
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the location ~ \.php(?:$|/) { block
location ~* \.(?:css|js)$ {
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
# Optional: Don't log access to other assets
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
access_log off;
}
}
Ich habe kopiert/eingefügt + modifizierte nginx Konfigurationscode, bezüglich ownCloud. Ich habe alles überprüft und es scheint in Ordnung zu sein. Was mache ich falsch? Warum kann ich nicht auf http://subdomain.example.com
zugreifen, ohne dass es an https://example.com
umgeleitet wird?
Sind Sie sicher, dass die Subdomänenkonfiguration geladen wird? "https: // subdomain.example.com" verweist möglicherweise immer noch auf die Hauptdomäne. –
@RichardSmith Ich habe Nginx erfolgreich oft neu gestartet, aber ohne Erfolg. – Nick
Beginnen Sie mit 'nginx.conf' und finden Sie die 'include'-Anweisungen und stellen Sie sicher, dass alle Ihre Konfigurationsdateien von' nginx' gelesen werden. –