Welcome! Log In Create A New Profile

Advanced

nginx second site configuration

Posted by rodusa 
nginx second site configuration
May 14, 2013 04:10PM
Please help me!!!!!!!!! I am trying to setup a second site using nginx but looks like all requests are going to the same place. I mean to this site here "institutoprana.com.br"

If you type in www.agencialojavirtual.br it goes to www.institutoprana.com.br.

What can I do to make the appropriate requests to go correctly to each domain?

server {
listen 80;


root /var/www/prana;
index index.php index.html index.htm;

server_name institutoprana.com.br;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9$
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include /etc/nginx/fastcgi_params;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}

server {
listen 80;
root /var/www/retiroaybrasilia;
index index.php index.html index.htm;
server_name agencialojavirtual.com.br;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}


Thank you
Re: nginx second site configuration
May 14, 2013 06:21PM
Hi rodusa,

You should probably start with defining server_name for instances of your supported domains
http://nginx.org/en/docs/http/server_names.html
and adding second configuration to enabled sites.



Edited 2 time(s). Last edit at 05/14/2013 06:24PM by vonHerman.
Re: nginx second site configuration
May 14, 2013 07:32PM
VonHerman,
In this config I combined the configuration of both domains and the server_name is in there. I also tried created two separated instances such as:
domain1
server {
...
server_name agencialojavirtual.com.br;
...
}

domain2
...
server_name agencialojavirtual.com.br;
...
}
and created symbolic links for them. I restarted nginx but that did not work too.

On my DNS server a have one A record for to www and another for * pointing to the server IP address.

I don't know what else to do. I have followed all tutorials and pretty much they all talk the same thing. Some say to separate the domain instances in separated files to facilitate management. Others use the other approach of putting everything in one file like I did above after I tried the other method.

Thanks
Re: nginx second site configuration
May 15, 2013 06:44AM
Looks like you have problem with dynamic content from PHP. Try asking new instance for some static content like:
http://agencialojavirtual.com.br/test.html
It it working?
Also make sure that:
nginx -t
output is clear.
Re: nginx second site configuration
May 15, 2013 08:42AM
VonHerman, Thank you very much for the tip. I did some play around after I read the link that you posted and I got it to work when I repeated the same config instructions from the one that was working. On the second one I also included the PHP fast cgi instructions which I believe is what made it work since these are both Wordpress sites. But I am aware that this is not the correct way to do since a single config file for all sites can be difficult to read and be unmanageable as it grows.

So I tried splitting the code for these 2 domains like this:
1. Under sites-available I created only one server section for each file and named them as domain1 and domain2
2. I enabled the sites using the ln -s /etc/nginx/sites-available/domain1 /etc/nginx/sites-enabled/domain1 and I enabled the sites using the ln -s /etc/nginx/sites-available/domain2 /etc/nginx/sites-enabled/domain2
3. Then I restarted nginx using sudo service nginx restart

But, unfortunately this approach did not work because now all requests are going to domain1. I don't know why is doing that?
I am not sure if nginx picks it as the default.

PS: I don't have the default attribute set under server_name. It sounds like it picks just one of the files an it is really weird that the second domain requests are going to the first one. According to that link that you gave the nginx should match the server_name exact name.

Thank you
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 180
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready