I am not able redirect my example.com request to www.example.com and they are now both different websites, pointing to the same application.
Background:
I have installed php 7 with nginx on Openshift ver. 2 using this. I have added 2 aliases for the application deployed, as follows:
- Application URL: myapp.rhcloud.com; Domain Name: www.example.com
- Application URL: myapp.rhcloud.com; Domain Name: example.com
I have also added the following DNS detailes in CNAME:
- Name: www.example.com; Value: myapp.rhcloud.com
- Name: @; Value: www.example.com
My nginx config file (erb) is as follows:
server {
root <%= ENV['OPENSHIFT_REPO_DIR'] %>/www;
listen <%= ENV['OPENSHIFT_PHP_IP'] %>:<%= ENV['OPENSHIFT_PHP_PORT'] %>;
server_name <%= ENV['OPENSHIFT_APP_DNS'] %>;
index index.php index.html index.htm <%= ENV['NGINX_EXTRA_INDEX'] %>;
set_real_ip_from <%= ENV['OPENSHIFT_PHP_IP'] %>;
real_ip_header X-Forwarded-For;
which becomes:
server {
root /path/to/my/app-root/folder/;
listen 127.11.2.1:8080;
server_name myapp.rhcloud.com;
index index.php index.html index.htm ;
set_real_ip_from 127.11.2.1;
real_ip_header X-Forwarded-For;
I have tried to add another server block in my nginx config file like the following:
server {
server_name example.com;
return 301 https://www.example.com$request_uri;
}
However I am not sure what should I use in place of example.com.