fgtr
fgtr

Reputation: 89

How to redirect the IP address of my server to the domain name?

I migrated my Drupal 8 site from an Apache server to a Nginx server. The domain name displayed the site but the IP address does not redirect to the domain name.

How to do this ?

Do I have to leave this IP address or put my IP address ?

I tested this block and it shows errors :

server {
listen 80;
listen [::]:80 ipv6only=on;
server_name domaine.com;
return 301 $scheme://www.domaine.com$request_uri;
root /var/www/www-domaine-com/web;

sudo nginx -t

nginx: [warn] conflicting server name "domaine.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "domaine.com" on [::]:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Upvotes: 1

Views: 429

Answers (2)

Toastlover
Toastlover

Reputation: 81

I understand that this Issue is already 5 Years old and the Poster may not have this issue anymore, however for anyone else who coomes across this Post, have a look at my Answer here, it could help you: https://stackoverflow.com/a/78833433/19050373

Upvotes: 0

Richard Smith
Richard Smith

Reputation: 49672

You need to roll back your changes to a working solution, because your current configuration looks like it breaks your site completely. The following lines appear to be spurious and need to be deleted, at the top of the first server block:

listen 80;
listen [::]:80 ipv6only=on;
return 301 $scheme://www.s1biose.com$request_uri;

Your site is accessed using https which cannot be contacted by IP address, without most browsers complaining about an invalid certificate.

However, you can easily arrange for all http connections to be redirected to your site, by changing the one line return 404; # managed by Certbot to return 301 https://example.com$request_uri;

The above assumes that there are no other server blocks in your configuration. You can use nginx -T (uppercase "T") to print the entire configuration as Nginx sees it, across all of its included files.

Upvotes: 0

Related Questions