AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 822359
Accepted
Sherif
Sherif
Asked: 2016-12-23 14:04:21 +0800 CST2016-12-23 14:04:21 +0800 CST 2016-12-23 14:04:21 +0800 CST

Nginx 强制 https 仅用于索引页面

  • 772

设置 nginx conf 以仅在 index.php 页面上强制 https 并且每个其他页面都强制为 http 的最佳方法是什么。

谢谢

http nginx https rules conf
  • 1 1 个回答
  • 337 Views

1 个回答

  • Voted
  1. Best Answer
    Tim
    2016-12-23T14:25:09+08:002016-12-23T14:25:09+08:00

    尝试这样的事情应该接近工作。我还没有测试它,所以可能会有错别字,但它至少应该给你一些指导。

    # You might address PHP some other way
    upstream php {
      server 127.0.0.1:9001;
    }
    
    server {
      server_name www.example.com example.com;
      listen 443 ssl http2;
      ssl_certificate /path/fullchain;
      ssl_certificate_key /path/privkey;
    
      # the index.php?$args is for wordpress, you can remove it
      try_files $uri $uri/ /index.php?$args; 
    
      # Single URL
      location = /index.php {
        # plus other PHP settings and parameters
        fastcgi_pass php; 
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    
      # Every other URL
      location / {
        return 301 http://www.example.com$request_uri;
      }
    
      # Run PHP scripts
      location ~ \.php$ {
        # plus other PHP settings and parameters
        fastcgi_pass php; 
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    }
    
    # Insecure server
    server {
      server_name www.example.com example.com;
      listen 80 default_server;
    
      # the index.php?$args is for wordpress, you can remove it
      try_files $uri $uri/ /index.php?$args; 
    
      location = /index.php {
        return 301 https://www.example.com/index.php;
      }
    
      location / {
        root /var/www/site;
      }
    
      location ~ \.php$ {
        # plus other PHP settings and parameters
        fastcgi_pass php; 
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    }
    
    • 1

相关问题

  • 设置 http 代理以使用 Web 界面?

  • 无法连接到 Ubuntu Desktop 中的端口 80 或 VMWare Workstation 6.52 中的 Server 9.04

  • IIS 7.5 (Windows 7) - HTTP 错误 401.3 - 未经授权

  • 为什么有些网站的网址中没有“www”就无法显示?[关闭]

  • Tomcat 6 HTTP 日志滚动和清除

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve