NGINX http到https如果只包含某些目录

NGINX http到https如果只包含某些目录,nginx,Nginx,我被指派了一对夫妇的项目。 我们的服务器上有两个目录,一个是 另一个是 我被要求做的是,如果有任何访问者登录到这两个目录(app和fw)中的某个页面,则将其从http重定向到https 以下是我到目前为止在配置文件中所做的工作。当我在“服务器”下面的配置文件中添加这些行并重新启动时,该站点将无法恢复。很遗憾,我没有访问日志文件的权限。感谢任何愿意看这个的人 location ~ ^/miner/memclub/.+\.html$ { rewrite ^(.+)\.html$ /boot

我被指派了一对夫妇的项目。 我们的服务器上有两个目录,一个是 另一个是

我被要求做的是,如果有任何访问者登录到这两个目录(app和fw)中的某个页面,则将其从http重定向到https 以下是我到目前为止在配置文件中所做的工作。当我在“服务器”下面的配置文件中添加这些行并重新启动时,该站点将无法恢复。很遗憾,我没有访问日志文件的权限。感谢任何愿意看这个的人

location ~ ^/miner/memclub/.+\.html$ {
    rewrite ^(.+)\.html$ /bootstrap.php?file=$1.html last;
    rewrite ^(.+)\.phtml$ /bootstrap.php?file=$1.phtml last;
    error_page 404 = /404.php;
}

server {
server_name site.org;
server_name *.site.org;
location /app {
     if ( $scheme = http ) {
     rewrite ^ https://site.org/app last;
     }
  }
}

首先,我不认为你可以有2个
服务器名称
,把这两行合并成一行

server_name example.com *.example.com;
要进行https重定向,我建议使用两个独立的服务器,您需要一个监听端口
443

server {
    server_name example.com www.example.com; # which ever you are using
    listen 443 ssl;
    location / {
        # all your https configuration
    }
}
server {
    server_name example.com www.example.com:
    listen 80;
    location /app {
        return 301 https://$http_host$request_uri;
    }
    location /fw {
        return 301 https://$http_host$request_uri;
    }
    location / {
        # the rest of the non https configuration
    }
}
我知道你可以将
app
fw
合并到一个位置,但我相信不使用正则表达式会更快,如果你想在这里实现的话

location /(app|fw) {
    return 301 https://$http_host$request_uri;
}