Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've successfully installed wordpress on an Amazon EC2 instance. It was working, however the apache service kept slowing down my machine and causing excess instances. Because of this, I have decided to switch to NGINX. It is already installed on my server. It is partially configured but I cannot get it fully working.

I am receiving 403 forbidden when accessing any folder directly and 502 bad gateway error when accessing and files directly.. Just so you know, I have 1 elastic IP and multiple domains that all point to that IP.

What I need is each domain to point to a different subdirectory or "root", with the first domain pointing to the highest level directory I.e:

domain1 > /var/www domain2 > /var/www/domain2.com domain3 > /var/www/domain3.com

Here is my nginx.conf file:

    # For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    index index.php index.html index.htm;

    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay        on;

    keepalive_timeout  10;

gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_comp_level 3; #You can vary this. 1 is least compression, 9 is most. I'll keep it low, since we have low CPU power.
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

server {
    listen 80;
    server_name www.mysites.com;
    access_log /var/www/access.log;
    error_log /var/www/error.log;
    root /var/www/myfolder/mysites.com;

  # Pass PHP scripts to PHP-FPM
        location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }

}






}
share|improve this question
2  
What is in the error log? –  Michael Hampton Mar 12 '13 at 12:02

1 Answer 1

If you have distinct domains, you should probably have separate server blocks.

server {
    listen 80;
    server_name domain1.com;
    access_log /var/www/access.domain1.log;
    error_log /var/www/error.domain1.log;
    root /var/www/domain1.com;
    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}
server {
    listen 80;
    server_name domain2.com;
    access_log /var/www/access.domain2.log;
    error_log /var/www/error.domain2.log;
    root /var/www/domain2.com;
    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}
server {
    listen 80;
    server_name domain3.com;
    access_log /var/www/access.domain3.log;
    error_log /var/www/error.domain3.log;
    root /var/www/domain3.com;
    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

Also, unless you need to, you shouldn't nest one sites content inside another. Best to keep them separate directories in case you ever need to move one to another server, say.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.