首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx服务器配置内子目录的ssl

问nginx服务器配置内子目录的ssl
EN

Stack Overflow用户
提问于 2012-01-27 01:04:13
回答 1查看 6.7K关注 0票数 4

我有一个启用了ssl的nginx服务器。目前,我已经为所有目录启用了https。如何只为www.example.com/shop/*目录启用ssl,而为其他目录禁用ssl??

下面是我的conf文件:

代码语言:javascript
复制
    # Redirect everything to the main site.
server {
  server_name *.example.com;
  listen 80;
  ssl on;
  ssl_certificate /opt/nginx/conf/server.crt;
  ssl_certificate_key /opt/nginx/conf/server.key; 
  keepalive_timeout    70;

  access_log  /home/example/nginx_logs/access.log ;
  error_log  /home/example/nginx_logs/error.log ;

  root /home/example/public_html/example.com;   
  location ~ \.php$ {
      try_files $uri $uri/ /index.php?q=$uri&$args;         
      root          /home/example/public_html/example.com/;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      include        /opt/nginx/conf/fastcgi_params;
      #fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script;
      fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
      fastcgi_param  SCRIPT_FILENAME  /home/example/public_html/example.com$fastcgi_script_name;
      index  index.php index.html index.htm;   
  }

    if ($http_host != "example.com") {
        rewrite ^ http://example.com$request_uri permanent;
    }

    include global/restrictions.conf;

    # Additional rules go here.

    #Only include one of the files below.
    include global/wordpress.conf;
#   include global/wordpress-ms-subdir.conf;
#   include global/wordpress-ms-subdomain.conf;
}

tnanks,D

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-27 23:57:05

这在Nginx中很容易实现。它涉及到两个步骤。

仅当访问您的域名.com/

  • 时,才会使用商店端口443。所有其他请求将被重定向到端口80 (HTTP)
  1. 端口80将检查您的域名/商店。如果找到,它将被重定向到端口443 (HTTPS)。

以下是如何实现的快速概述……

代码语言:javascript
复制
server {
  listen 443;
  server_name yourdomain.com;

  # directives for SSL certificates

  # root, index, error_log, access_log directives

  location /shop {
    # directives to handle what's inside /shop, for example
    # try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    # directives to handle PHP files
  }

  # leave everything else to port 80
  location / {
    rewrite ^ http://$host$request_uri permanent;
  }
}

server {
  listen 80;
  server_name yourdomain.com;

  # root, index, error_log, access_log directives

  # redirect yourdomain.com/shop to port 443
  # Please put this before location / block as
  # nginx stops after seeing the first match
  location /shop {
    rewrite ^ https://$host$request_uri permanent;
  }

  location / {
    # directives to handle what's inside /, for example
    # try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    # directives to handle PHP files
  }

}
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9022102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档