Jun 1, 2015
8
Level 51
HTTP to HTTPS Nginx/Forge
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;
}
Level 65
It will if you do this in the same file
server {
listen 80;
listen [::]:80; // probably don't need this if you don't want to listen on IPv6
server_name www.crm.domain.com crm.domain.com;
return 301 https://crm.domain.com$request_uri;
}
server {
listen 443 ssl;
# 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;
server_name www.crm.domain.com;
return 301 https://crm.domain.com$request_uri;
}
server {
// original server block
}
Like it is in my post but I've just done it for you... :) https://bashy.im/blog/nginx-redirect-to-https-with-without-www-subdomain
7 likes
Please or to participate in this conversation.