English 中文(简体)
nginx redirect HTTPS to HTTP
原标题:

How can i redireect from https to http?

i have the code below but it does not seem to work.

server {
        listen 443;
        server_name example.com;
        rewrite ^(.*) http://example.com$1 permanent;
 }
问题回答

The answer above will work, you need to generate a self signed cert (or have a real one) and configure nginx as such:

server {
  listen *:443;
  ssl on;
  server_name domain.com;
  rewrite ^(.*) http://domain.com$1 permanent;

  ssl_certificate      /data/certs/domain.crt;
  ssl_certificate_key  /data/certs/domain.key; 
 }

Keep in mind, if it is a self signed cert the browser will give you an ugly warning.

Building off jberger s comment a configuration that should work would be:

server {
    listen *:80;
    server_name example.com;
}

server {
    listen              *:443 ssl;
    server_name         example.com;
    ssl_certificate     /etc/ssl/certs/example.com.cert;
    ssl_certificate_key /etc/ssl/private/example.com.key;
    return 301 http://$server_name$request_uri;
}
    if ($host =  foo.com ) {
        rewrite  ^/(.*)$  http://www.foo.com$1  permanent;
    }




相关问题
How should I use https in Ruby on Rails

I m developing an application in Rails (2.3.4) and there are some parts that need to run over a secure protocol, for example, the login form, the credit card form, etc. How can I do just these pages ...

How to open a stream to httpS URL

I want to open a stream to a httpS URL and read the data. Kindly let me know how to do it. Regards Chaitanya

direct http to https on certain pages?

Hi I have added the below code to .ht access but how can I add another page to this? such as login.php also if the user types in www. they get a "untrusted connection" as the SSL is only valid ...

See what content is not sent over HTTPS

I created a page that is HTTPS only. On my browsers, I always get a warning that the page includes resources that are not secured. I just can t find out why! Looking at the source code seems fine. All ...

C# maintaining session over HTTPS on the client

I need to login to a website and perform an action. The website is REST based so I can easily login by doing this (the login info is included as a querystring on the URL, so I dont t need to set the ...

热门标签