1. Setting up the FTP server
In order to upload the project file to the cloud server, we need to set up the FTP service on the cloud server to carry out the file transfer.
(1) Cloud server side
A. First, we need to install VSFTPD, enter the command
sudo apt-get install vsftpd-y
B. After the installation is successful, we need to create an FTP dedicated account.
Check the location of the Nologin folder, usually under/usr/sbin/nologin or/sbin/nologin. If you do not have this folder, create a new one under/sbin.
After entering Nologin, enter the command:
useradd-d%storage_path%-s/sbin/nologin%user_name%
Where Storage_path is the location after the file is uploaded, User_name is the user name to use for the FTP link.
Then enter:
passwd%user_name%
Set a password for the user you just created.
After that, you need to authorize the user, enter the command:
Chown-r%user_name%.%user_name%%storage_path%
C. Configuring VSFTP
Edit the Vsftp configuration file with the following command:
Vi/etc/vsftpd.conf
Change "Anonymous_enable=yes" in the configuration file to "Anonymous_enable=no"
Remove the comment symbol before the following configuration:
Local_enable=yes
Write_enable=yes
Chroot_local_user=yes
Chroot_list_enable=yes
Chroot_list_file=/etc/vsftpd.chroot_list
Save exit
Edit the/etc/vsftpd.chroot_list file (if it does not exist, create a new one), add the FTP account name, save the exit
D. Modify the shell
VI Edit/etc/shells, if there is no/usr/sbin/nologin or/sbin/nologin in the file (depending on the current system configuration) is appended
E. Restart VSFTPD Service
Service VSFTPD Restart
(2) Local side
In order to upload files to the server, local need to install LFTP
sudo apt-get install lftp
Then, enter the command
Lftp Username:[email protected]:21
127.0.0.1 is a local IP and should be modified here to be the public IP address of your cloud server. After that, you will enter the LFTP command line, where the operating directory is already on the cloud server side.
The upload file has the following command:
Put%file_name% upload a single file
mput *.txt Batch Upload TXT file
Mirror%folder_name% Upload entire folder
Then your code is uploaded to the cloud server, and the next step is to deploy it to Apache.
2. Apache + Mod_wsgi + Django
First install Apache:
sudo apt-get install apache2
You need to make some changes to the configuration file, in/etc/apache2/apache2.conf, the last line is added:
ServerName localhost
Then install WSGI:
sudo apt-get instal libapace2-mod-wsgi
Then restart the server:
Apachectl restart
The next step is to write the Django project to the configuration file. Add at the end of apache2.conf:
Wsgiscriptalias//path/to/mysite.com/mysite/wsgi.pywsgipythonpath/path/to/mysite.com < /path/to/mysite.com/mysite><wsgi.py> Require All granted </ Files > </ Directory >
Next, you need to change the access permissions for the directory where the project resides. Enter the following command:
Chmod-r 775/path/to/mysite.com
Restart the server again.
If Django is not installed on the server, enter:
Pip Install django==1.8.3
At this point, the configuration is basically complete. From the public IP access, you can see the project page.
Deploying a Django project to a cloud server