【问题标题】:nginx exclude path from httpsnginx 从 https 中排除路径
【发布时间】:2018-07-18 06:46:11
【问题描述】:

我正在尝试使用 nginx 从 https 中排除路径 client 和包含 client 的每个 url。

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 文件。我在浏览器中看到太多重定向。

【问题讨论】:

  • 您在第一个 server 块中缺少 rootindex 语句。
  • @RichardSmith 非常感谢!我一直在测试一整天,我一直在寻找重定向问题。

标签: php ssl redirect nginx nginx-location


【解决方案1】:

感谢https://stackoverflow.com/users/4862445/richard-smith

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

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

        root /var/www/laravel/public; #LINE-ADDED

        index index.php index.html index.htm; #LINE-ADDED

        # other code here ...
}

【讨论】:

    猜你喜欢
    • 2014-02-04
    • 1970-01-01
    • 2021-03-30
    • 2020-04-04
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多