Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to setup nginx with ssl, to serve some static HTML and the output of some Python scripts (through uwsgi). It works fine with HTTP, but I am not able to make it run on HTTPS, as nginx is returning a "301 Moved Permanently" matter the URI (i.e., even for those that do not exist).

I am currently using a self-signed certificate and my idea is to force HTTPS connections. What am I doing wrong? Does it look like an nginx configuration problem?

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

server {
  listen 443 ssl;
  ssl_certificate /srv/ssl/nginx.pem;
  ssl_certificate_key /srv/ssl/nginx.key;
  location / {
    rewrite ^ https://$server_name$request_uri? permanent;

(obviusly, stands for the actual server name).

Edit: Typos.

share|improve this question
Does it eventually show the page? Your rewrite forces a 301 redirection on the client since you're forcing SSL. – Nathan C Dec 10 '13 at 22:30

1 Answer 1

up vote 1 down vote accepted

Your rewrite rule is in the wrong place: it applies (only) to the server block which does SSL already. Your browser might have been already complaining about a never-ending redirect.

Put the rewrite rule in the server block which listens on Port 80, without SSL.

share|improve this answer
Thank you, it was so simple and obvious! – Giacomo Dec 11 '13 at 21:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.