I'm answering this although it's been accepted because I think the answer is wrong.
I'm pasting your config below as-is, with only a comment pointing to the wrongly placed (extra it seems) curly bracked closing the server block:
server { listen 443 ssl default_server; server_name example.com server_tokens off; charset utf-8;} <--------- CLOSED BLOCK WITH EXTRA BRACKET... SSL config stuff ... location / { proxy_pass http://localhost:8000/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Proxy ""; }}server { listen 80; server_name example.com return 301 https://$host$request_uri;}
The recommended way is to use the $host
as you had it initially. The $server_name
variable will be replaced by the virtualhost definition instead of the URL entered by the user. This could cause you problems if you are using server_alias for example. You can read the definition of each variable in the official nginx documentation. Here is a quote:
$server_name name of the server which accepted a request $host in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request
So. I think your problem was the curly bracket, and not the variable. You should probably return to the $host and try again if it works.
ps. also remove the proxy_http_version
line and the proxy_set_header
with the empty "", they are not needed unless you have a very specific use-case.