让学习成为一种习惯!

Nginx环境下http和https可同时访问方法

服务器 06-06 10:39:54 编辑:张丹
【www.xuexiya.com - 服务器】

  server {

  listen 80 default backlog=2048;

  listen 443;

  server_name xuexiya.com;

  root /var/www/html;

  ssl on;

  ssl_certificate /usr/local/Tengine/sslcrt/lvtao.net.crt;

  ssl_certificate_key /usr/local/Tengine/sslcrt/lvtao.net.key;

  }

  http访问的时候,报错如下:

  400 Bad Request

  The plain HTTP requset was sent to HTTPS port. Sorry for the inconvenience.

  Please report this message and include the following information to us.

  Thank you very much!

  说是http的请求被发送到https的端口上去了,所以才会出现这样的问题。

  server {

  listen 80 default backlog=2048;

  listen 443 ssl;

  server_name  xuexiya.com;

  root /var/www/html;

  ssl_certificate /usr/local/Tengine/sslcrt/lvtao.net.crt;

  ssl_certificate_key /usr/local/Tengine/sslcrt/lvtao.net.Key;

  }

  把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用,完美解决。