To help explain my issue, let me create an analogous, but fictional backstory.
Let's say I have a friend, Sarah, who makes her living through a web cam. And let's say this source of income is supporting Sarah's 4 year old, Lisa.
I met Sarah because she contracted me to write her a custom adult webcam site. She also introduced me to Lisa's preschool, who has also contracted me to write their site.
To save money, I host both sites using the same server, through Nginx.
I excitedly notify the school about all the progress I've made on their
website! What I couldn't have known is that my node process that was serving
lisas-preschool.com
was down.
After an awkward phone call, I discover that sometimes Nginx will serve the wrong content for the site visited.
This obviously can't happen, EVER! So, how do I make sure that
sarahs-site.com
and lisas-preschool.com
will never be cross-served?
For reference, here's the configurations for the sites:
lisas-preschool.com:
This is a node.js site:
upstream lisas_preschool {
server 127.0.0.1:3000;
}
# HTTP Server
server {
listen 0.0.0.0:80;
server_name www.lisas-preschool.com lisas-preschool.com;
access_log /var/log/nginx/lisas-preschool.access;
location / {
proxy_pass http://lisas-preschool.com;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
}
}
sarahs-site.com
This is a wordpress site:
server {
listen 80;
listen [::]:80;
server_name sarahs-site.com www.sarahs-site.com;
index index.php index.html index.htm;
root /var/www/sarahs-site.com/html;
location / {
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/site-b.com/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}