不能在同一个NGINX服务器下运行两个分离的网站

我试图使用nginx在同一台服务器上运行两个分离的站点。 根据configuration的不同,nginx在两个域名下服务于一个站点或另一个站点。 它不会在自己的域上运行每个站点。

有任何想法吗? 谢谢!

更新:我试过迈克尔·汉普顿的build议,但服务器不启动时,有两个server_name指令。 如果我评论一下,nginx开始,但只运行一个网站。

此外, service nginx configtest只适用于一个server_name,两个server_name失败。

configuration文件如下:

在/ etc / nginx的/网站可用/的Joomla

 server { listen 80; server_name n-pix.com; root /var/www/n-pix; index index.php index.html index.htm default.html default.htm; error_log /var/log/nginx/joomla.error.log info; # Support Clean (aka Search Engine Friendly) URLs location / { try_files $uri $uri/ /index.php?$args; } client_max_body_size 1024M; server_tokens off; # deny running scripts inside writable directories location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ { return 403; error_page 403 /403_error.html; } location ~ \.php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # caching of files location ~* \.(ico|pdf|flv)$ { expires 1y; } location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ { expires 14d; } } 

在/ etc / nginx的/网站可用/ jarbas

 upstream unicorn { server unix:/tmp/unicorn.jarbas.sock fail_timeout=0; } server { listen 80; server_name jarbas.n-pix.com; root /home/deployer/apps/jarbas/current/public; error_log /var/log/nginx/jarbas.error.log info; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 1G; keepalive_timeout 10; } 

你已经混淆了你的listenserver_name指令。

listen应包含您希望服务器侦听的端口(可选IP / IPv6地址)。

server_name应该包含服务器的主机名。

例如(这个configuration需要nginx 1.3.4或更高版本):

 listen 80; listen [::]:80; server_name n-pix.com; 

 listen 80; listen [::]:80; server_name jarbas.n-pix.com; 

更新configuration文件后,我运行了nginx -t

 nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 nginx: configuration file /etc/nginx/nginx.conf test failed 

所以我添加了server_names_hash_bucket_size 64;nginx.conf

 http { (...) server_names_hash_bucket_size 64; (...) } 

现在一切正常。 多谢你们!