Hi, So i’m trying to configure a new, second server_block and although ‘site2.com’ works , ‘www.site2.com’ redirects to my previously set up ‘default’ site. I’m unsure where i’m going wrong?
Site2; ##DEFAULT CONFIG BELOW##
server
{
listen 80;
server_name www.site2.com site2.com;
return 301 http://www.site2.com$request_uri;
}
server {
listen 80;
listen [::]:80;
server_name site2.com;
root /var/www/site2.com/;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
-> To clarify, ‘default’ is my original site which works fine (and is SSL certified) while site2 (above) is the new site i’m trying to add (for the moment it is non-SSL certified, trying to certify it lead to a whole other list of problems)
Default; ##CONFIG BELOW##
server {
listen 80 default_server ;
listen [::]:80 default_server ipv6only=on;
server_name default.com www.default.com;
return 301 https://www.default.com$request_uri;
}
server{
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include /etc/nginx/snippets/ssl-default.com.conf;
include /etc/nginx/snippets/ssl-params.conf;
location ~ /.well-known {
allow all;
}
root /var/www/default.com/site;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
-> Another additional piece of info, originally someone helped me establish my first server_block so my ‘default’ site (or site1 if you prefer) runs out of sites-enabled/default. Is there a problem with this? Site2 is in its own file with appropriate naming convention. I’ve just never had more than one site so i’m unsure if leaving site1’s code running in the default file is alright.
Any help is very much appreciated. Thank you.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
server
{
listen 80;
server_name www.site2.com site2.com;
return 301 http://www.site2.com$request_uri;
}
server {
listen 80;
listen [::]:80;
server_name site2.com;
root /var/www/site2.com/;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Currently the first block here creates an endless loop for www.site2.com. In the server_name block you should add www.site2.com and remove it from the redirect block.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.