nginx反向代理服务器,无法访问没有路径的域

时间:2019-03-25 16:04:56

标签: nginx nginx-reverse-proxy nginx-config

根据指南,我确实设置了nextcloud docker容器和nginx反向代理。一切正常,除了当我无任何路径访问域时,都会收到“访问被拒绝”错误。

https://cloud.domain.de:“访问被拒绝。”

例如这个,或任何带有路径的东西:https://cloud.domain.de/login:有效

domain.de.conf

upstream php-handler {
    server unix:/run/php/php7.2-fpm.sock;
}

server {
        listen 80 default_server;
        server_name cloud.domain.de domain.de 172.123.123.57;

        root /var/www/;

        location ^~ /.well-known/acme-challenge {
                proxy_pass http://127.0.0.1:81;
                proxy_redirect off;
        }

        location / {
                # Enforce HTTPS
                # Use this if you always want to redirect to the DynDNS address (no local access).
                return 301 https://$server_name$request_uri;
        }
}

server {
        listen 443 ssl http2;
        server_name cloud.domain.de 192.168.178.60;
        root /var/www/nextcloud/;
        # Certificates used
        ssl_certificate /etc/letsencrypt/live/domain.de/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.de/privkey.pem;
        ssl_protocols TLSv1.2 TLSv1.3;

        ssl_ciphers '123123';
        ssl_dhparam /etc/nginx/ssl/dhparams.pem;

        # Use multiple curves.
        # secp521r1: Not supported by Chrome
        # secp384r1: Not supported by Android (DAVdroid)
        ssl_ecdh_curve secp521r1:secp384r1:prime256v1;

        # Server should determine the ciphers, not the client
        ssl_prefer_server_ciphers on;

        # OCSP Stapling
        # fetch OCSP records from URL in ssl_certificate and cache them
        ssl_stapling on;
        ssl_stapling_verify on;

        # This should be chain.pem
        # See here: https://certbot.eff.org/docs/using.html
        ssl_trusted_certificate /etc/letsencrypt/live/domain.de/chain.pem;

#       resolver 192.168.178.1;
        # SSL session handling
        ssl_session_timeout 24h;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains" always;
        add_header X-Content-Type-Options "nosniff" always;
        # Usually this should be "DENY", but when hosting sites using frames, it has to be "SAMEORIGIN"
        add_header Referrer-Policy "same-origin" always;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;

        #
        # Nextcloud
        #
        location ~ / {
                # Set max. size of a request (important for uploads to Nextcloud)
                client_max_body_size 10G;
                # Besides the timeout values have to be raised in nginx' Nextcloud config, these values have to be raised for the proxy as well
                proxy_connect_timeout 3600;
                proxy_send_timeout 3600;
                proxy_read_timeout 3600;
                send_timeout 3600;
                proxy_buffering off;
                proxy_request_buffering off;
                proxy_max_temp_file_size 10240m;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://127.0.0.1:82;
                proxy_redirect off;
        }
}

domain.de_nextcloud.conf

server {
    listen 127.0.0.1:82;
    server_name 127.0.0.1;

    # Add headers to serve security related headers
    # Use 'proxy_set_header' (not 'add_header') as the headers have to be passed through a proxy.
    proxy_set_header Strict-Transport-Security "max-age=15768000; includeSubDomains; always;";
    proxy_set_header X-Content-Type-Options "nosniff; always;";
    proxy_set_header X-XSS-Protection "1; mode=block; always;";
    proxy_set_header X-Robots-Tag none;
    proxy_set_header X-Download-Options noopen;
    proxy_set_header X-Permitted-Cross-Domain-Policies none;

    # Path to the root of your installation
    root /var/www/nextcloud;

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

    location = /.well-known/carddav {
                return 301 $scheme://$host/remote.php/dav;
        }
    location = /.well-known/caldav {
                return 301 $scheme://$host/remote.php/dav;
        }

    location /.well-known/acme-challenge { }

    location ^~ / {
        # set max upload size
        client_max_body_size 10G;
        fastcgi_buffers 64 4K;
        # Enable gzip but do not remove ETag headers
        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject 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;
        #pagespeed off;

        location / {
            rewrite ^ /index.php$uri;
        }

        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }

        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

        location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
   # Raise timeout values.
            # This is especially important when the Nextcloud setup runs into timeouts (504 gateway errors)
            fastcgi_read_timeout 600;
            fastcgi_send_timeout 600;
            fastcgi_connect_timeout 600;
            fastcgi_request_buffering off;            
            fastcgi_param PHP_VALUE "open_basedir=/var/www:/tmp/:/var/cloud_data:/dev/urandom:/proc/meminfo:/
                                upload_max_filesize = 10G
                                post_max_size = 10G
                                max_execution_time = 3600
                                output_buffering = off";

            # Make sure that the real IP of the remote host is passed to PHP.
            fastcgi_param REMOTE_ADDR $http_x_real_ip;
        }

        location ~ ^/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri/ =404;
            index index.php;
        }

        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~* \.(?:css|js)$ {
            try_files $uri /index.php$uri$is_args$args;
            proxy_set_header Cache-Control "public, max-age=15778463";
            # Add headers to serve security related headers
            # Again use 'proxy_set_header' (not 'add_header') as the headers have to be passed through a proxy.
            proxy_set_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
            proxy_set_header X-Content-Type-Options nosniff;
            #proxy_set_header X-Frame-Options "SAMEORIGIN";
            proxy_set_header X-XSS-Protection "1; mode=block";
            proxy_set_header X-Robots-Tag none;
            proxy_set_header X-Download-Options noopen;
            proxy_set_header X-Permitted-Cross-Domain-Policies none;
            # Optional: Don't log access to assets
            access_log off;
        }

        location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
            try_files $uri /index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
}

这两个配置文件中有什么问题导致此问题?

0 个答案:

没有答案