nginx从https中排除路径

时间:2018-02-07 20:44:38

标签: php ssl redirect nginx nginx-location

我正在尝试使用nginx从https中排除路径客户端以及包含客户端的每个网址。

server {
        listen 80;
        server_name example.com www.example.com;


        location / {
                return 301 https://www.example.com$request_uri;
        }

        location /client/ {
                try_files $uri $uri/ /index.php?$query_string;

        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

}

server {

        listen 443 ssl;
        server_name example.com www.example.com;


        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


        root /var/www/laravel/public;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
        }

        location /client/ {
                return 301 http://www.example.com$request_uri;

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }

        location ~ /.well-known {
                allow all;
        }

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                expires 30d;
                add_header Vary Accept-Encoding;
                access_log off;
        }
}

我从第二个服务器块中删除了ssl证书密钥。

当我输入https://example.com/client时,我会被重定向到http://www.example.com/client(正如预期的那样)。我在客户端文件夹中有一个简单的index.php文件没有被执行。我在浏览器中看到太多的重定向。

1 个答案:

答案 0 :(得分:0)

归功于https://stackoverflow.com/users/4862445/richard-smith

在第一个服务器块中添加了根和索引语句。

class DeepDialog {
    @Embedded lateinit var embedded: Dialog
    @Relation(parentColumn = "id", entityColumn = "dialogId", entity = Message::class)
    lateinit var messages: List<DeepMessage>
}

class DeepMessage {
    @Embedded lateinit var embedded: Message    
    @Relation(parentColumn = "id", entityColumn = "messageId", entity = ImageContent::class)
    lateinit var imageContents: List<DeepImageContent>
}

... etc