How to stop 301 error only on https, http works fine?

I’ve managed to get rid of the 301 redirect error on my http domain name by removing this line from my nginx config file

return 301 https://$server_name$request_uri;

When I run

curl -I -L

I get

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 05 Mar 2019 13:33:42 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 31 Jan 2017 15:01:11 GMT
Connection: keep-alive
ETag: "5890a6b7-264"
Accept-Ranges: bytes

But since I have Let’s Encrypt redirecting all traffic from http to https, I can’t access my domain name without the 301 error.

The https page still has that error.

curl -I -L


HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.3 (Ubuntu)
Date: Tue, 05 Mar 2019 13:49:07 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive

curl: (47) Maximum (50) redirects followed

Can someone help me to fix the 301 error on the https page?

nginx config file

server {
listen 80;
servertokens off;

server {
listen 443 ssl; # managed by Certbot

ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot  

root /home/me/myapp/src/myapp;

location = /favicon.ico { access_log off; log_not_found off; }

location /static/ {
    root /home/me/myapp/src/myapp;

location /media/  {
    root /home/me/myapp/src/myapp;

location / {
    try_files $uri/ @python_django;

location @python_django {
    proxy_pass_request_headers on;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_redirect off;

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I had the same issue with my site but then i came to know that canonicalization is more effective then just the URL 301s and is also Google friendly as well if you need any help regarding the URL Canonicalization just ping me back i’ll be happy to help.


HTTP code 301 is not an error. It’s a permanent redirect. Your app is the one possibly redirecting to So that’s where you need to check.