现在试图让这个Django项目运行一个多星期了,但绝对没有运气了。我现在试图通过流浪汉来运行它,但现在我遇到了问题。如果有人能提供任何帮助,我将非常感激。我只是想让Vagrant启动并运行,但我收到403 Forbidden错误。我在Windows 8机器上运行。
这是我的输出:
这是我的vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "hashicorp/precise64"
config.vm.provision :shell, path: "provision.sh"
config.vm.provision :shell, path: "nice-env.sh"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
这是我的provision.sh文件:
#!/bin/bash
# Directory of the Django project
BASEDIR=/vagrant
# The apache user
WEBUSER=vagrant
SERVERNAME=192.168.33.10
SQLROOTPASS=6zXAHftMRFGhn4DsYfdsH6dw
DBNAME=cfmt
DJANGOUSER=cfmt
DJANGOPASS=CesVoucrud
debconf-set-selections <<< "mysql-server-5.5 mysql-server/root_password password $SQLROOTPASS"
debconf-set-selections <<< "mysql-server-5.5 mysql-server/root_password_again password $SQLROOTPASS"
apt-get update
apt-get install -y git apache2 libapache2-mod-wsgi python python-pip python-dev mysql-client mysql-server libmysqlclient-dev
pip install virtualenv
echo Setting up virtualenv
cd $BASEDIR && virtualenv venv
if [ $? -eq 0 ]
then
VENV=$BASEDIR/.venv
else
echo NOTE: Windows does not allow symlinks in the /vagrant directory, so virtualenv has been installed in /var/cfmt-venv
cd /var && virtualenv cfmt-venv
VENV=/var/cfmt-venv
fi
echo Installing python dependencies using pip
$VENV/bin/pip install -r $BASEDIR/requirements.txt
# Fix weird module location issue
ln -s $BASEDIR $BASEDIR/../cfmt
echo Installing settings_local.py
cat > $BASEDIR/settings_local.py <<EOL
# Fix weird module location issue
import sys
sys.path.append("$BASEDIR/..")
DEBUG = True
# If sqlite3 doesn't cut it, we may need to switch the dev env back to MySQL,
# and solve the from-scratch migration issues
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': '$DBNAME',
# 'USER': '$DJANGOUSER',
# 'PASSWORD': '$DJANGOPASS',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '$BASEDIR/database.sqlite'
}
}
MEDIA_URL = 'http://192.168.33.10/media/'
EOL
echo Updating apache site
cat > /etc/apache2/sites-available/cfmt.conf <<EOL
WSGIDaemonProcess webclient user=$WEBUSER group=$WEBUSER threads=25 python-path=$BASEDIR:$BASEDIR/..:$VENV/lib/python2.7/site-packages
WSGIProcessGroup webclient
WSGIPassAuthorization On
WSGIScriptAlias / $BASEDIR/sites/cfmt/conf/cfmt.wsgi
WSGIPythonPath $BASEDIR
<VirtualHost *:80>
ServerName $SERVERNAME
DocumentRoot $BASEDIR/media
<Directory $BASEDIR/media>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory $VENV/lib/python2.7/site-packages/django/contrib/admin/media>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
Alias /adminmedia/ $VENV/lib/python2.7/site-packages/django/contrib/admin/media/
Alias /media/ $BASEDIR/media/
Alias /static/ $BASEDIR/media/
</VirtualHost>
EOL
cd /etc/apache2/sites-enabled && ln -s -f ../sites-available/cfmt.conf 100-cfmt.conf
rm -f /etc/apache2/sites-enabled/000-default*
a2dismod autoindex
service apache2 restart
if [ ! -f /var/db-inited ]
then
echo Initializing database
mysql -uroot -p$SQLROOTPASS <<EOL
CREATE DATABASE $DBNAME CHARACTER SET utf8;
CREATE USER '$DJANGOUSER'@'localhost' IDENTIFIED BY '$DJANGOPASS';
GRANT ALL PRIVILEGES on $DBNAME.* TO '$DJANGOUSER'@'localhost';
GRANT ALL PRIVILEGES on test_$DBNAME.* TO '$DJANGOUSER'@'localhost';
FLUSH PRIVILEGES;
EOL
touch /var/db-inited
fi
echo Creating upload directories
#mkdir -p $BASEDIR/static/uploads
#chown -R $WEBUSER:$WEBUSER $BASEDIR/static/uploads
echo Running syncdb
$VENV/bin/python $BASEDIR/manage.py syncdb --noinput
echo Running migrations
$VENV/bin/python $BASEDIR/manage.py migrate
echo Seeding model fixtures
$VENV/bin/python $BASEDIR/manage.py loaddata $BASEDIR/fixtures/cfmt.json
答案 0 :(得分:1)
问题似乎不是流浪者,而是配置脚本或机器配置中的某些内容。这很难说,因为我没有脚本,但我会开始寻找,特别是如果它正在编辑apt更新列表或其他东西。我还要查看版本要求,对于Ubuntu 12.04来说这可能太新了,这就是你的basebox正在运行的。