nginx / unit-docs

NGINX Unit's official website and documentation
https://unit.nginx.org
Creative Commons Attribution 4.0 International
51 stars 101 forks source link

Add how to specify a virtual environment for Python Applications #3

Closed goodtune closed 5 years ago

goodtune commented 6 years ago

Ref: https://www.nginx.com/blog/unit-0-3-beta-release-available-now/

luzfcb commented 5 years ago

a sample:

python virtualenv directory in a different path from the project directory:

I have the following structure:

Virtualenvs:

/home/server_user/.virtualenvs/
├── venv1
│   ├── bin
│   │   └── python
│   ├── include
│   └── lib
└── venv2
    ├── bin
    │   └── python
    ├── include
    └── lib

django projects:

/home/server_user/projects/
├── project1
│   ├── logs
│   └── src
│       ├── apps
│       ├── config
│       │   └── wsgi.py
│       ├── .env
│       └── manage.py
└── project2
    ├── logs
    └── src
        ├── apps
        ├── config
        │   └── wsgi.py
        ├── .env
        └── manage.py

unit:

{
    "applications": {
        "project1": {
            "type": "python 2.7",
                        "user": "server_user",
                        "group": "server_user",
            "processes": 8,
                        "working_directory": "/home/server_user/projects/project1/src/",
                        "path": "/home/server_user/projects/project1/src/",
            "module": "config.wsgi",
            "home": "/home/server/.virtualenvs/venv1"
        },
        "project2": {
            "type": "python 3.5",
                        "user": "server_user",
                        "group": "server_user",
            "processes": 8,
                        "working_directory": "/home/server_user/projects/project2/src/",
                        "path": "/home/server_user/projects/project2/src/",
            "module": "config.wsgi",
            "home": "/home/server/.virtualenvs/venv2"
        },
    },

    "listeners": {
        "*:8000": {
            "application": "project1"
        },
                "*:9000": {
            "application": "project2"
        }
    }
}

full context: https://github.com/nginx/unit/issues/151#issuecomment-405249583

ghost commented 5 years ago

Hello,

Thank you for your contribution!