I have an nginx webserver hosting an old site. This site has been migrated to a new site but I want to keep the old site live on a subdomain, legacy2.example.com. I've gone through and modified the sites-enabled and sites-available config files and linked them, as well as created an A record to legacy2.example.com pointing to this IP, however it is still redirecting to domain.com, not legacy2.example.com. I'm including my config file below. Is there some other config in nginx that could be telling it to redirect?
I've followed along with similar questions and basic guides, but even with changing the server_name field I can't seem to get
server {
listen 80;
listen [::]:80;
server_name legacy2.example.com wwww.legacy2.example.com;
location /.well-known {
root /var/www/prod.example.com/current;
try_files $uri =404;
}
location / {
if ($http_user_agent ~* SemrushBot|ByteSpider|YandexBot|AhrefsBot|DotBot) {
return 403;
}
return 301 https://$http_host$request_uri;
}
}
server {
listen 8080;
listen [::]:8080;
server_name legacy2.example.com wwww.legacy2.example.com;
set $MAGE_ROOT /var/www/prod.example.com/current;
set $MAGE_MODE production;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include /var/www/prod.example.com/current/nginx.conf.sample;
error_log /var/log/nginx/prod.example.com.error.log;
access_log /var/log/nginx/prod.example.com.access.log;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name legacy2.example.com wwww.legacy2.example.com;
ssl_certificate "/etc/nginx/ssl/example.com.pem";
ssl_certificate_key "/etc/nginx/ssl/example.com.key";
client_max_body_size 128M;
error_log /var/log/nginx/prod.example.com.error.log;
access_log /var/log/nginx/prod.example.com.access.log;
# Enable to bypass Varnish
# set $MAGE_ROOT /var/www/prod.example.com/current;
# set $MAGE_MODE production;
# include /var/www/prod.example.com/current/nginx.conf.sample;
# Varnish
location / {
if ($http_user_agent ~* SemrushBot|ByteSpider|YandexBot|AhrefsBot|DotBot) {
return 403;
}
proxy_pass http://127.0.0.1:6081;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Ssl-Offloaded "1";
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
# proxy_set_header X-Forwarded-Proto $scheme;
#proxy_headers_hash_max_size 512;
#proxy_headers_hash_bucket_size 128;
}
}