A
A
AprilSnow2015-06-03 18:10:30
Nginx
AprilSnow, 2015-06-03 18:10:30

How to make a config for two sites?

The first site should be on a subdomain, and next to it should be a landing page (one index.html) site on the main domain.
The config now looks like this:

server {
  listen 81;
  server_name example.example.com;
  access_log /var/log/nginx/example.log;
  

  location /static/ {
      root /opt/myenv/example_dir;
      expires 30d;
  }


  location / {
      proxy_pass http://127.0.0.1:8000;
      proxy_set_header Host $server_name;
      proxy_set_header X-Real_IP remote_addr;
      proxy_set_header X-Forwarded-Proxy $proxy_add_x_forwarded_proxy;
  }
       

} 

server {
  listen 80;
  server_name example.com;
  
  location / {
      root /opt/myenv/example_dir_2;
      index index.html;
}

       

}

What should I change to make it all work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Shikanov, 2015-06-03
@AprilSnow

listen 80 must be on both the first and second host.

S
ShamblerR, 2015-06-03
@ShamblerR

well, for starters, write everything you need into the second server, otherwise there you have some kind of emptiness and dullness in general;)

server {
                        server_name www.lorena-salon.ru;
                                        access_log  /var/log/ispconfig/httpd/$host/access.log;
                                        location / {
                                        index index.php index.html index.htm;
                                        root /var/www/lorena-salon.ru/web/;
                                        proxy_pass http://www.lorena-salon.ru:82;
                                        proxy_set_header X-Real-IP  $remote_addr;
                                        proxy_set_header Host $host;
                                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

server {
                        server_name www.kredo-m.ru;
                                        access_log  /var/log/ispconfig/httpd/$host/access.log;
                                        location / {
                                        index index.php index.html index.htm;
                                        root /var/www/kredo-m.ru/web/;
                                        proxy_pass http://www.kredo-m.ru:82;
                                        proxy_set_header X-Real-IP  $remote_addr;
                                        proxy_set_header Host $host;
                                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question