How to add virtualhosts in nginx?

Hello All,

Following the excellent guide posted in cyberciti.biz
(http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/)
I istalled nginx in centos 5.5 successfully, but I fail to configure
VirtualHosts.

I tried different combinations but it does not work.

Could someone please help me?

I just need an example of a working configuration.

I really appreciate it.

Best Regards,
Marcelo .-

On 22 Set 2010 06h45 WEST, [email protected] wrote:

I just need an example of a working configuration.

http://wiki.nginx.org/NginxVirtualHostExample

— appa

Thank you António,

I saw this example before.

I saw many examples, but does not work.

I get always nginx default html page or 404…

2010/9/22, António P. P. Almeida [email protected]:

nginx mailing list
[email protected]
http://nginx.org/mailman/listinfo/nginx


¿Por qué sufrimos? http://www.youtube.comwatch?v=FK53c2jW2VU

Hola António and everybody,

Thanks for the help, I really apreciate it!

The VirtualHosts configuration file is located in:
/etc/nginx/conf.d/virtual.conf

example:

http {

vhost1 - www.prueba.com

server {
listen 80;
server_name www.prueba.com;
access_log logs/prueba.access.log main;

index index.html;
root /var/www/virtuales/prueba.com/htdocs;
}

2010/09/22 13:21:22 [info] 24429#0: the configuration file
/etc/nginx/nginx.conf syntax is ok
2010/09/22 13:21:22 [emerg] 24429#0: open()
“/usr/share/nginx/logs/prueba.access.log” failed (2: No such file or
directory)
2010/09/22 13:21:22 [emerg] 24429#0: the configuration file
/etc/nginx/nginx.conf test failed

¿the logs file must be created maually everytime I create a domain?

I remove the “access_log logs/prueba.access.log main;” line and
works,
but when I browse “www.prueba.com” I get nginx default html page, and
when I
browse “www.prueba.com/index.html” the index.html placed in
/var/www/virtuales/prueba.com/html is showed.

is possible show index.html directly when “prueba.com” or
www.prueba.com
is entered in the browser?

Maybe some redirection in the VirtualHost configuration file

what about the error logs files?

Thank you very much!

2010/9/22 António P. P. Almeida [email protected]

On 22 Set 2010 07h21 WEST, [email protected] wrote:

Thank you António,

I saw this example before.

I saw many examples, but does not work.

I get always nginx default html page or 404…

Then there’s something wrong with your configuration. Perhaps the root
directive or a/the location block. This is guessing. It’s much better
if you place the config here, so that we can help you debug it.

— appa

On 22 Set 2010 19h32 WEST, [email protected] wrote:

vhost1 - www.prueba.com

2010/09/22 13:21:22 [info] 24429#0: the configuration file
/etc/nginx/nginx.conf syntax is ok
2010/09/22 13:21:22 [emerg] 24429#0: open()
“/usr/share/nginx/logs/prueba.access.log” failed (2: No such file or
directory)
2010/09/22 13:21:22 [emerg] 24429#0: the configuration file
/etc/nginx/nginx.conf test failed

¿the logs file must be created maually everytime I create a domain?

No. You can specify the log file in a server context and use the $host
variable.

access_log /var/log/nginx/$host/access.log

Although in the wiki such practice is discouraged:
http://wiki.nginx.org/NginxHttpLogModule#access_log So yes the best
practice is to set an access log for each domain.

You have to specify a full path otherwise nginx will use a default
path. You can specify a default log file in the --http-log-path
configure option.

I remove the “access_log logs/prueba.access.log main;” line and
works, but when I browse “www.prueba.com” I get nginx default html
page, and when I browse “www.prueba.com/index.html” the index.html
placed in /var/www/virtuales/prueba.com/html is showed.

is possible show index.html directly when “prueba.com” or
www.prueba.com” is entered in the browser?

Yes.

Maybe some redirection in the VirtualHost configuration file

Nope. It’s the access log error.

what about the error logs files?

See above.

Fix the access log error. Nginx isn’t loading the configuration. It’s
using a
previous one.

See http://wiki.nginx.org/CommandLine, the HUP signal handling to be
specific.

— appa

Hello,

On Wed, 22 Sep 2010 15:32:55 -0300
Marcelo [email protected] wrote:

vhost1 - www.prueba.com

2010/09/22 13:21:22 [info] 24429#0: the configuration file
/etc/nginx/nginx.conf syntax is ok
2010/09/22 13:21:22 [emerg] 24429#0: open()
“/usr/share/nginx/logs/prueba.access.log” failed (2: No such file or
directory)
2010/09/22 13:21:22 [emerg] 24429#0: the configuration file
/etc/nginx/nginx.conf test failed

¿the logs file must be created maually everytime I create a domain?

is the directory really existing ? Nginx will only create the file, not
the path.

Cheers,

C.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs