D
D
deadnice2020-12-25 20:22:39
Nginx
deadnice, 2020-12-25 20:22:39

How to properly configure nginx when transferring a domain to another hosting?

I am moving to another hosting. For https I use CloudFlare Proxy. How to redirect to another hosting correctly when changing dns for a domain (so that ssl does not fall off)?

sites-available/default on origin server
server {
listen 443 ssl;
server_name somedomain.com;

ssl on;
ssl_certificate /etc/nginx/ssl3/domain_name.chained.crt;
ssl_certificate_key /etc/nginx/ssl3/private.key;

location /images/ava/ {
  alias /var/www/public/images/ava/;
}

location /nginx_status {
          stub_status on;
          access_log off;
          allow someipaddress;
          allow someipaddress;
          deny all;
}

location / {
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
}

server {
listen 80;
proxy_set_header Host somedomain.com;
location / {
rewrite ^(.*)$ https://somedomain.com$1 permanent;
}
}

sites-available/default on target server
server {
server_name _;

location /images/ava/ {
  alias /var/www/public/images/ava/;
}

location /nginx_status {
          stub_status on;
          access_log off;
          allow someipaddress;
          allow someipaddress;
          deny all;
}

location / {
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
}

server {
listen 80;

}

How should these files change?

Apache listens on port 8080
<VirtualHost *:8080>
  ServerAdmin [email protected]
  DocumentRoot /var/www/public
  ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2021-01-05
@deadnice

Just change the ip in cloudflare and everything will be fine, nothing else needs to be done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question