Vagrant框内的Wordpress安装会重定向回http:// localhost

时间:2016-01-13 10:19:40

标签: wordpress nginx vagrant

当我浏览到浏览器中的Vagrant框的端口转发URI(在本例中为http://localhost:9001)时,我遇到了一个奇怪的问题,我被重定向回localhost(默认服务器)。我不确定为什么会这样,而且真的令人沮丧。

在我的来宾机器上,我有/ var / www / wordpress中托管的根文件夹,这是我的/ nginx / sites-available / nginx_vhost文件:

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    root /var/www/wordpress;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
            # try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    location ~* \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            #fastcgi_read_timeout 300;
            #proxy_read_timeout 300;
    }

}

这是我的Vagrant文​​件:

Vagrant.configure("2") do |config|

# Set Vagrant box to use
config.vm.box = "ubuntu/trusty64"

# Configure port forwarding
config.vm.network :forwarded_port, guest: 80, host: 9001, auto_correct: true

# Set synched folder
config.vm.synced_folder "./", "/var/www/wordpress", create: true, group: "www-data", owner: "www-data"

# Configure the VM
config.vm.provider "virtualbox" do |v|
    v.name = "Pet Vets Vagrant Box"
    v.customize ["modifyvm", :id, "--memory", "1024"]
end

# Set up shell provisioning
config.vm.provision :shell, :path => "bootstrap.sh"

我的bootstrap.sh文件:

#!/bin/bash

echo "Provisioning virtual machine..."
apt-get update

echo "Installing Tree..."
apt-get install tree

echo "Installing Git"
apt-get install git -y > /dev/null

echo "Installing Nginx"
apt-get install nginx -y >/dev/null

echo "Configuring Nginx"
cp /var/www/wordpress/nginx_vhost /etc/nginx/sites-available/nginx_vhost > /dev/null

ln -s /etc/nginx/sites-available/nginx_vhost /etc/nginx/sites-enabled/nginx_vhost

rm /etc/nginx/sites-available/default

service nginx restart > /dev/null

echo "Updating PHP repository"
apt-get install python-software-properties build-essential -y > /dev/null
add-apt-repository ppa:ondrej/php5 -y > /dev/null
apt-get update > /dev/null

echo "Installing PHP"
apt-get install php5-common php5-dev php5-cli php5-fpm libssh2-php -y > /dev/null

echo "Installing PHP extensions"
apt-get install curl php5-curl php5-gd php5-mcrypt php5-mysql -y > /dev/null
apt-get install libapache2-mod-php5

当我在本地(不使用Vagrant)将它托管在nGinx上时,Wordpress安装工作正常,但是一旦我将它放在Vagrant框中,它就不想播放。有没有人有任何想法?

谢谢!

1 个答案:

答案 0 :(得分:0)

所以问题不在于nGinx它与Wordpress配置有关。

我在wp_options表中的siteurl和home都设置为http :: localhost,需要将其设置为http://localhost:9001

希望这有助于将来的任何人!

由于