theUnforgiven
5 years ago
1090
8
Forge

HTTP to HTTPS Nginx/Forge

Posted 5 years ago by theUnforgiven

Using Laravel Forge (nginx) I have this in my nginx config:

server {
    listen 80;
    listen 443 ssl;

    server_name crm.domain.com;
    root /home/forge/crm.domain.com/public;
    
    

    # FORGE SSL (DO NOT REMOVE!)
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_certificate /etc/nginx/ssl/crm.domain.com/7947/server.crt;
    ssl_certificate_key /etc/nginx/ssl/crm.domain.com/7947/server.key;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

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

    access_log off;
    error_log  /var/log/nginx/default-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

How can I set up a permenant redirect so if a user types,

www.crm.domain.com or crm.domain.com it would just redirect them to https://crm.domain.com ?

I have tried the following but doesn't redirect:

server {
    server_name crm.domain.com;
    rewrite ^/(.*) https://crm.domain.com/$1 permanent;
}

Please sign in or create an account to participate in this conversation.