G
G
Grag2014-06-25 16:00:17
Nginx
Grag, 2014-06-25 16:00:17

Why does nginx redirect everything to the same file?

Hello.
I created a couple of virtual hosts, and by ip address everything opens ok, but by name it redirects to the same thing, and does not open the host itself.
What could be the problem?
nginx.conf

worker_processes  2;
 
error_log  /usr/local/etc/nginx/logs/error.log debug;
 
events {
    worker_connections  1024;
}
 
http {
    include             mime.types;
    default_type        application/octet-stream;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  /usr/local/etc/nginx/logs/access.log  main;
 
    sendfile            on;
    keepalive_timeout   65;
 
    index index.html index.php;
    
    include /usr/local/etc/nginx/sites-enabled/*;
    
    
}

example of one of the hosts:
server {

   listen 81;

   server_name work.dev www.work.dev;
   root /private/var/www/work.dev/www;
   
   index index.php;

   access_log /private/var/www/work.dev/logs/access.log;
   error_log /private/var/www/work.dev/logs/error.log;
   
   ssl                  on;
   ssl_certificate      ssl/work.dev.crt;
   ssl_certificate_key  ssl/work.dev.key;

   ssl_session_timeout  5m;

   ssl_protocols  SSLv2 SSLv3 TLSv1;
   ssl_ciphers  HIGH:!aNULL:!MD5;
   ssl_prefer_server_ciphers   on;
   
   location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
   }
   
     
   include   /usr/local/etc/nginx/conf.d/php-fpm;
}

/etc/hosts file:
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

127.0.0.1       test.dev
127.0.0.1       work.dev
127.0.0.1       hiwork.dev
127.0.0.1       learning.dev

Help, very urgent.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Antony Ryabov, 2014-06-25
@tonymadbrain

1. And what for to register in host?
2. Nginx has two default configs default.conf and ssl.conf. In default.conf, the server is set as "default", i.e. if you left it active, then all domains will go there.
3. And what OS do you use?

Константин Сахинов, 2014-06-27
@sakhinov

Аналогичная ситуация. По прошествии двух дней разобрался. Пытался редиректить на внутренние виртуальные хосты, однако все запросы падали на один виртуальный хост. Помогало только разбрасывание по разным портам. Но это не правильно!
Методом тыка выяснил, что nginx для определения к какому хосту адресован запрос, нужно передавать http-заголовок Host.
В моем случае помогло
proxy_set_header Host $reproxy_host;
, где $reproxy_host - адресуемый виртуальный хост.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question