Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 02-12-2014, 11:05 PM   #1
Registered: Aug 2007
Posts: 339

Rep: Reputation: 31
nginx force all http to https help

I did do a bunch of reading and testing and can't get anything to change. This is my first run-in with nginx so still feeling around, but basically we want ALL http traffic to switch to https.

The only thing is there is a wildcard cert, so the server_name includes the wildcard, but the whole config is under one server;

server {
server_name localhost *;
listen 80;
listen [::]:80;
listen 443 ssl;

When I hit the URL I see the following in the logs; - - [12/Feb/2014:22:58:49 -0500] "GET /favicon.ico HTTP/1.1" 400 672 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"

And I am greeted with a 400,
400 Bad Request
The plain HTTP request was sent to HTTPS port

Now, when I change the browser to https all works as expected. I did try separating a single server for http and another with https, with a 301 redirect, but got nothing. Since I am so new, figured I would post this while I continued to read.

Old 02-13-2014, 03:43 AM   #2
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,216

Rep: Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407

You may use the following rewrite:
server {
    listen         80;
    return 301 https://$host$request_uri;


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Nginx Proxy to HTTP and HTTPS LXer Syndicated Linux News 0 06-03-2013 07:30 PM
ssh over http using nginx haxwithaxe Linux - Server 2 01-11-2012 11:06 PM
how to force nginx to do DNS lookups fancylad Linux - Server 6 06-06-2011 02:01 AM
Force use HTTPS on spectacular URL?? wegadnie Linux - Networking 2 04-09-2009 04:31 AM
Force https on a password protected directory abapdr Linux - Software 1 06-07-2004 05:35 AM

All times are GMT -5. The time now is 07:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration