Всем привет.
***Отредактировано чуть позже***
nginx на файл для поддомена ругается
nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/test_project:1
Нашел лог nginx
2015/04/16 15:10:21 [warn] 21356#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:10:22 [warn] 21367#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:17:04 [warn] 21958#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:17:05 [warn] 21969#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:32:29 [warn] 23276#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:32:30 [warn] 23287#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:36:35 [warn] 23658#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:36:36 [warn] 23669#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:41:04 [warn] 24170#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:41:05 [warn] 24181#0: conflicting server name "test.site.ru" on 0.0.0.0:80, ignored
2015/04/16 15:43:32 [error] 24185#0: *127 open() "/var/www/project/public/static/css/images/ui-bg_highlight-soft_100_eeeeee_1x100.png" failed (2: No such file or directory), client: 95.53.152.43, server: project, request: "GET /static/css/images/ui-bg_highlight-soft_100_eeeeee_1x100.png HTTP/1.1", host: "site.ru", referrer: "
site.ru/static/css/style.4a8835c4cb00954c1f79b9472..."
2015/04/16 15:49:47 [error] 24185#0: *354 open() "/var/www/project/public/favicon.ico" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /favicon.ico HTTP/1.1", host: "site.ru"
2015/04/16 15:58:54 [error] 24185#0: *651 open() "/var/www/project/public/favicon.ico" failed (2: No such file or directory), client: 178.64.190.31, server: project, request: "GET /favicon.ico HTTP/1.1", host: "site.ru"
2015/04/16 16:12:42 [emerg] 25484#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/test_project:12
2015/04/16 16:14:13 [emerg] 25558#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/test_project:12
2015/04/16 16:16:26 [emerg] 25653#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/test_project:12
2015/04/16 16:20:02 [emerg] 25774#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/test_project:12
2015/04/16 16:20:10 [error] 25588#0: *130 open() "/var/www/project/public/favicon.ico" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /favicon.ico HTTP/1.1", host: "test.site.ru"
2015/04/16 16:36:39 [error] 25588#0: *665 open() "/var/www/project/public/static/images/111.png" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /static/images/111.png HTTP/1.1", host: "test.site.ru"
2015/04/16 16:37:12 [error] 25588#0: *681 open() "/var/www/project/public/static/images/111.png" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /static/images/111.png HTTP/1.1", host: "test.site.ru"
2015/04/16 16:38:12 [error] 25588#0: *709 open() "/var/www/project/public/static/images/111.png" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /static/images/111.png HTTP/1.1", host: "test.site.ru"
2015/04/16 16:58:14 [error] 25588#0: *1326 open() "/var/www/project/public/static/images/111.png" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /static/images/111.png HTTP/1.1", host: "test.site.ru"
2015/04/16 16:58:19 [error] 25588#0: *1330 open() "/var/www/project/public/static/images/111.png" failed (2: No such file or directory), client: 91.215.204.246, server: project, request: "GET /static/images/111.png HTTP/1.1", host: "site.ru"
2015/04/16 17:09:23 [emerg] 30254#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/test_project:12
2015/04/16 17:13:05 [emerg] 30472#0: "error_log" directive is not allowed here in /etc/nginx/sites-enabled/test_project:3
2015/04/16 17:15:14 [emerg] 30537#0: open() "/usr/share/nginx/./test_project" failed (2: No such file or directory)
2015/04/16 17:15:34 [emerg] 30549#0: "upstream" directive is not allowed here in /etc/nginx/sites-enabled/test_project:1
2015/04/16 17:18:50 [emerg] 30649#0: "error_log" directive is not allowed here in /etc/nginx/sites-enabled/test_project:3
2015/04/16 17:19:11 [emerg] 30661#0: "upstream" directive is not allowed here in /etc/nginx/sites-enabled/project:1
***
Есть такая задача. Есть сайт site.ru. на нем крутится статика через nginx и django через gunicorn.
Необходимо создать поддомен test.site.ru, чтобы на нем, грубо говоря, крутился второй сайт. Я сделал следующим образом:
Создал двух пользователей: один для site.ru другой для test.site.ru. создал для каждого свое виртуальное окружение. Для каждого сделал свой файл настроек для nginx, каждому в виртуально окружение установил через pip supervisor. Статика и пользовательские файлы лежат в /var/www/project/public. В управлении, где мне предоставляют сервер, сделал запись test.site.ru A 111.222.333.444 ttl 30min, site.ru крутится на этом же ip. у каждого юзера в папке /home//etc лежат настройки gunicorn для supervisord.
Привожу все настройки
Главный сайт site.ru:
nginx:
upstream project_server {
server 127.0.0.1:8888 fail_timeout=0;
}
server {
listen 80;
server_name www.site.ru;
rewrite ^/(.*) http://site.ru/$1 permanent;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name project;
large_client_header_buffers 8 32k;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_disable "msie6";
gzip_comp_level 5;
gzip_types text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json;
keepalive_timeout 5;
root /var/www/project/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_send_timeout 1000s;
proxy_read_timeout 1000s;
if (!-f $request_filename) {
proxy_pass http://project_server;
break;
}
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
expires max;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/project;
}
}
gunicorn:
[program:gunicorn]
command=/home/<user1>/.env/bin/gunicorn --workers=3 --worker-connections=1000 --worker-class=gunicorn.workers.ggevent.GeventWorker
--bind=127.0.0.1:8888 project.wsgi:application --timeout=300 --graceful-timeout=10
directory=/home/<user1>/current
environment=DJANGO_SETTINGS_MODULE="project.settings.production"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/<user1>/log/gunicorn.log
теперь настройки для test.site.ru
nginx:
upstream test_project_server {
server 127.0.0.1:8001 fail_timeout=0;
}
server {
listen 80;
server_name test.site.ru;
rewrite ^/(.*) http://test.site.ru/$1 permanent;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name test.site.ru;
large_client_header_buffers 8 32k;
keepalive_timeout 5;
root /var/www/project/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_send_timeout 1000s;
proxy_read_timeout 1000s;
if (!-f $request_filename) {
proxy_pass http://test_project_server;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/project;
}
}
gunicorn
command=/home/<user2>/.env/bin/gunicorn --workers=3 --worker-connections=1000 --worker-class=gunicorn.workers.ggevent.GeventWorker
--bind=127.0.0.1:8001 project.wsgi:application --timeout=300 --graceful-timeout=10
directory=/home/<user2>/current
environment=DJANGO_SETTINGS_MODULE="project.settings.test"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/<user2>/log/gunicorn.log
Главный сайт работает полностью.
Тестовый нет, выдает 500.
Есть еще такой факт, что когда я удаляю конфиг nginx для поддомена и перезапускаю nginx (service nginx restart) он пишет, что * restarting nginx, а если добавляю конфиг то он молча выполняется... Но статика на test.site.ru работает.
Вобщем я весь запутался и даже не знаю куда копать...