LINUX.ORG.RU
решено ФорумAdmin

nginx+2 домена и разные папки


0

0

Привествую. Есть настроенный nginx для 1 домена. Нужно добавить еще 2 домена и чтобы у каждого была отдельная папка. Может кто поможет как сделать?

Вот мой конфиг:

user nginx;
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
server_name gentoo;


charset utf-8;

location / {
root /var/www/**/htdocs;
index index.php index.html index.htm;
}

location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/***/htdocs$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/***/htdocs;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
}
}

ось gentoo

ls /etc/nginx
fastcgi_params  koi-utf  koi-win  mime.types  nginx.conf  win-utf

nginx+2 домена и разные папки

добавь еще пару секций server { ... } (внутри секции http {...} ) и поменяй root(впиши туда пути к папкам) и server_name(впиши туда свои доменные имена).

drull ★☆☆☆ ()

nginx+2 домена и разные папки

location запихнуть внутрь server{...}. и worker_processes увеличить на всякий случай. типа того:

user nginx;
worker_processes 5;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
server_name gentoo;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/***/htdocs$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/***/htdocs;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/gentoo/htdocs;
index index.php index.html index.htm;
}

server {
listen 80;
server_name gentoo2;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/***/htdocs$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/***/htdocs;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/gentoo2/htdocs;
index index.php index.html index.htm;
}

server {
listen 80;
server_name ubuntu;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/***/htdocs$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/***/htdocs;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/ubuntu/htdocs;
index index.php index.html index.htm;
}


}
}

drull ★☆☆☆ ()
Ответ на: nginx+2 домена и разные папки от drull

Re: nginx+2 домена и разные папки

сделал такой конфиг

user nginx;
worker_processes 5;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
server_name doin.ru;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/***/htdocs;
index index.php index.html index.htm;
}

server {
listen 80;
server_name domain.org;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/****/htdocs;
index index.php index.html index.htm;
}

}
}

ругается

* Checking nginx' configuration...
[emerg]: "server" directive is not allowed here in /etc/nginx/nginx.conf:41
configuration file /etc/nginx/nginx.conf test failed
* failed, please correct errors above                                     [ !! ]

ClanMax ()
Ответ на: Re: nginx+2 домена и разные папки от ClanMax

nginx+2 домена и разные папки

скобку не там поставил случайно. вот так надо:

user nginx;
worker_processes 5;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
server_name doin.ru;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/****/htdocs$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/****/htdocs;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/***/htdocs;
index index.php index.html index.htm;
}
}

server {
listen 80;
server_name domain.org;
charset utf-8;
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/****/htdocs$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param  DOCUMENT_ROOT    /var/www/****/htdocs;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  REQUEST_URI      $request_uri;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  REMOTE_USER      $remote_user;
            fastcgi_param  REMOTE_ADDR      $remote_addr;
            fastcgi_param  REMOTE_PORT      $remote_port;

}
location / {
root /var/www/****/htdocs;
index index.php index.html index.htm;
}
}
}

и еще:

            fastcgi_param  SCRIPT_FILENAME  /var/www/$fastcgi_script_name;

            fastcgi_param  DOCUMENT_ROOT    /var/www/;
для каждого server{...} должен быть свой, ну и пути соответствующие (поменяй на то что написано в root соответствующего servera).

drull ★☆☆☆ ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.