Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Trying to get multiple server blocks working

$
0
0
I'm working on CentOS 6.4, Nginx 1.0.15 with php and mysql.

I have two hosts I have in mind, www.domain1.com and sub.domain1.com. The default server had been set to localhost and it works just fine. The " include /etc/nginx/conf.d/*.conf; " had been uncommented in "/etc/nginx/nginx.conf" as well.


So I created two files inside "/etc/nginx/conf.d" folder

[code]
[compunuts@f150 conf.d]$ pwd
/etc/nginx/conf.d
[compunuts@f150 conf.d]$ ls
default.conf domain1.conf sub-domain1.conf
[compunuts@f150 conf.d]$
[/code]

Inside each file has config like this.

domain1.conf
[code]
server {
listen 80;
server_name www.domain1.com;
root /usr/local/ngnix/html/domain1;
index index.php index.html index.htm;
error_log /var/log/nginx/domain1/error.log;
access_log /var/log/nginx/domain1/access.log main;

location ~ \.php$ {
root /usr/local/nginx/html/domain1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_$
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php;
}
}
[/code]

sub-domain1.conf
[code]
server {
listen 80;
server_name sub.domain1.com;
root /usr/local/ngnix/html/sub-domain1;
index index.php index.html index.htm;
error_log /var/log/nginx/sub-domain1/error.log;
access_log /var/log/nginx/sub-domain1/access.log main;

location ~ \.php$ {
root /usr/local/nginx/html/sub-domain1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_$
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php;
}
}
[/code]

I have index.html file and info.php file inside both root directories. But when I put the url in the browser, it got "500 Internal Server Error" message. If I type localhost, it rendered to default page.

What am I doing wrong here? I read " http://wiki.nginx.org/ServerBlockExample " page and it says to put those in but didn't mention which file to put it in. Should I be putting in inside nginx.conf file?

Any pointer is highly appreciated. Thanks.

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>