0

I'm struggling to find what's causing an HTTPS redirection in my nginx server. I have even started a new vagrant box to test it without any luck, so I'm starting to believe it doesn't have anything to do with my local vagrant box.

I'm using Mac OSX High Sierra in my computer, and an Ubuntu 16.04 for my local server in my vagrant box.

As I described, I'm constantly getting an HTTPS redirection for my domain, and SSL is not enabled in my nginx server.

Here is my nginx configuration (vhost.conf):

server {
  listen 80;

  root /var/www/example.dev/html;
  index index.php;

  server_name example.dev;
  sendfile off;

  location / {
      try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  # pass the PHP scripts to FastCGI server listening on /tmp/php7.0-fpm.sock
  #
  location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $fastcgi_script_name =404;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_index index.php;
        include fastcgi.conf;
  }
}

In my nginx.conf I have the following content:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

And in my /etc/hosts file, I added the following so I can access the Vagrant server from my mac (yes, 192.168.50.100 is the IP of the vagrant server, it's been checked):

192.168.50.100 example.dev

If I do a wget request from my mac, I do get the returned contents of my server, without any HTTPS redirection.

I definitely need help with this.

  • Did you the entry in the /etc/hosts on the mac, or on the Ubuntu system? /etc/hosts is only relevant for the client system in this scenario. – vidarlo Mar 23 '18 at 13:23
  • On the mac. I've checked to rename the domain to something completely different, and it seems it only happens with domains ending in .dev, since only changing the domain to example.com and changing the hosts file in my mac made it work. – xarlymg89 Mar 23 '18 at 13:27
  • Have you checked all of your enabled sites and configuration blurbs in /etc/nginx/sites-enabled and /etc/nginx/conf.d/*.conf to see if there's any SSL redirections going on there? Have you confirmed that whatever is running PHP is not redirecting the URL itself to HTTPS? (Wordpress, Joomla, etc. all can do that without configuration editing) – Thomas Ward Mar 23 '18 at 13:32
  • The nginx config seemed to be OK. I have renamed the server to a different TLD (I had been using .dev now I use .local), and it works. 2 different vagrant machines, with totally different setups, (Ubuntu 14.04 and Ubuntu 16.04), and they both behaved the same way. Now, the 16.04, JUST changing the name worked. Strange. – xarlymg89 Mar 23 '18 at 15:25
1

This is the most awkward thing I have experienced while setting up a server. Just changing the servername did the 'trick'.

I was using .dev TLDs. I changed it to .local and voilà! Server working. Same configurarion, countless service nginx restart, 2 different vagrant machines with 2 different versions of Ubuntu, and still got the same results.

Even changing the server.conf for a totally different one.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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