S
S
skorpix2015-04-16 17:00:20
Django
skorpix, 2015-04-16 17:00:20

Django how to create site for change testing?

Hello.
***Edited a little later***
nginx on the file for the subdomain
nginx swears: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/test_project:1
Found the nginx log
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,
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
***
There is such a task. There is a website site.ru. it spins static through nginx and django through gunicorn.
It is necessary to create a test.site.ru subdomain so that, roughly speaking, the second site is spinning on it. I did the following: I
created two users: one for site.ru and the other for test.site.ru. created for each its own virtual environment. For each, I made my own settings file for nginx, installed each in a virtual environment via pip supervisor. The static and user files are in /var/www/project/public. In the management, where they provide me with a server, I made an entry test.site.ru A 111.222.333.444 ttl 30min, site.ru is spinning on the same ip. each user in the /home//etc folder has gunicorn settings for supervisord.
Here are all the settings
Main site 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

now settings for 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

The main site is fully functional.
The test one does not, it gives out 500.
There is also such a fact that when I delete the nginx config for the subdomain and restart nginx (service nginx restart), it says that * restarting nginx, and if I add the config, then it is silently executed... But the static on the test .site.ru works.
In general, I'm all confused and I don't even know where to dig ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
skorpix, 2015-04-17
@skorpix

All in all, I solved the problem. Thanks for the tip sim3x .
It was all about the nginx configs, which, in principle, is logical.
In the config of the main site site.ru, I changed default to default_server. In principle, nothing has changed, because. there used to be a default directive, then it was replaced with default_server, but the behavior is the same.
But the second config was cut almost completely. I will give, then I will try to explain what mistakes were made.

upstream test_project_server {
    server 127.0.0.1:8001 fail_timeout=0;
}

server {
    listen 80;
    client_max_body_size 4G;
    server_name test.site.ru;
    access_log  /home/test_project/log/nginx_access.log;
    keepalive_timeout 5;

    root /var/www/project/public;

    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /var/www/project;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://test_project_server;
            break;
        }
     }
}

Two sections of the server were sawn out. Only one remained. This is done because there should be only one default_server in the configs, and if there are two servers in one config, he does not know which one to contact.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question