0

I'm fairly new to Nginx and web servers in general.

My setup is docker, Nginx, PHP/laravel, +let's encrypt.

I have this Nginx config file:

server {
    listen 80;
    server_name www.example.io;
    return 301 https://example.io$request_uri;
}

server {
    listen 80;
    server_name example.io;
    return 301 https://example.io$request_uri;
}

server {
    listen 443 ssl;
    server_name example.io;
    ssl_certificate /etc/nginx/certs/example.io.pem;
    ssl_certificate_key /etc/nginx/certs/example.io.key;

    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

I'm pretty sure my certificates are not what the problem is. because they do work when I have a single port 80 server and it has server_name example.io www.example.io but in that case, I'm unable to access the website through example.io as secure. while the www.example.io is secure. it also acts like two different websites. I believe the cookies in one do not implement in the other.

What I'm trying to achieve is, I wish to redirect both www.example.io and example.io to https://example.io

Darryl E. Clarke
  • 7,286
  • 3
  • 24
  • 34
Agil
  • 346
  • 4
  • 20
  • Are you literally using "example.io"? Does "example.io" resolve to the IP address you expect? A quick `dig example.io` shows no domain by that name registered, so you would have to map in your hosts file to get the domain to resolve anywhere. – PaulProgrammer Mar 01 '20 at 20:22
  • of course not :D @PaulProgrammer – Agil Mar 01 '20 at 20:25
  • Do you add example.io to your /etc/hosts file? (on windows this file has another location) – Denys Kurbatov Mar 01 '20 at 20:26
  • yeah it's in the hosts file. and previously it was working properly as http. – Agil Mar 01 '20 at 20:27
  • I'm suspicious about the config file, the reason must be it. – Agil Mar 01 '20 at 20:29
  • Are there any error messages? What's the nginx start-up message look like? Re the cookies issue, there is a ton of info on that out there, you could start with https://stackoverflow.com/questions/18492576/share-cookie-between-subdomain-and-domain – ldg Mar 01 '20 at 21:19
  • I start it over `docker-compose` the container build successfully nothing seems to be wrong. @ldg – Agil Mar 01 '20 at 22:13
  • The first thing to check is the nginx/PHP logfiles. What do they say? – Don't Panic Mar 02 '20 at 03:11
  • There is no log in either of them – Agil Mar 02 '20 at 05:54

0 Answers0