Node.js 游荡节点Nginx Dev VM

Node.js 游荡节点Nginx Dev VM,node.js,nginx,vagrant,vagrantfile,Node.js,Nginx,Vagrant,Vagrantfile,我正在尝试使用Vaprobash为节点项目获取一个可重用的文件。我在设置的Nginx部分遇到了麻烦。这是Vaprobash Nginx.sh设置文件: #!/usr/bin/env bash # Test if PHP is installed php -v > /dev/null 2>&1 PHP_IS_INSTALLED=$? echo ">>> Installing Nginx" [[ -z "$1" ]] && { echo "

我正在尝试使用Vaprobash为节点项目获取一个可重用的文件。我在设置的Nginx部分遇到了麻烦。这是Vaprobash Nginx.sh设置文件:

#!/usr/bin/env bash

# Test if PHP is installed
php -v > /dev/null 2>&1
PHP_IS_INSTALLED=$?

echo ">>> Installing Nginx"

[[ -z "$1" ]] && { echo "!!! IP address not set. Check the Vagrant file."; exit 1; }

if [ -z "$2" ]; then
    public_folder="/vagrant"
else
    public_folder="$2"
fi

# Add repo for latest stable nginx
sudo add-apt-repository -y ppa:nginx/stable

# Update Again
sudo apt-get update

# Install the Rest
sudo apt-get install -y nginx

echo ">>> Configuring Nginx"

if [[ $PHP_IS_INSTALLED -eq 0 ]]; then

    read -d '' PHP_NO_SSL <<EOF
        # pass the PHP scripts to php5-fpm
        # Note: \.php$ is susceptible to file upload attacks
        # Consider using: "location ~ ^/(index|app|app_dev|config)\.php(/|$) {"
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
            fastcgi_param LARA_ENV local; # Environment variable for Laravel
            fastcgi_param HTTPS off;
        }
EOF

    read -d '' PHP_WITH_SSL <<EOF
        # pass the PHP scripts to php5-fpm
        # Note: \.php$ is susceptible to file upload attacks
        # Consider using: "location ~ ^/(index|app|app_dev|config)\.php(/|$) {"
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
            fastcgi_param LARA_ENV local; # Environment variable for Laravel
            fastcgi_param HTTPS off;
        }
EOF
else
    PHP_NO_SSL = ""
    PHP_WITH_SSL = ""
fi

# Configure Nginx
# Note the .xip.io IP address $1 variable
# is not escaped
cat > /etc/nginx/sites-available/vagrant << EOF
server {
    listen 80;

    root $public_folder;
    index index.html index.htm index.php app.php app_dev.php;

    # Make site accessible from http://set-ip-address.xip.io
    server_name $1.xip.io;

    access_log /var/log/nginx/vagrant.com-access.log;
    error_log  /var/log/nginx/vagrant.com-error.log error;

    charset utf-8;

    location / {
        try_files \$uri \$uri/ /app.php?\$query_string /index.php?\$query_string;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    $PHP_NO_SSL

    # Deny .htaccess file access
    location ~ /\.ht {
        deny all;
    }
}

server {
    listen 443;

    ssl on;
    ssl_certificate     /etc/ssl/xip.io/xip.io.crt;
    ssl_certificate_key /etc/ssl/xip.io/xip.io.key;

    root $public_folder;
    index index.html index.htm index.php app.php app_dev.php;

    # Make site accessible from http://set-ip-address.xip.io
    server_name $1.xip.io;

    access_log /var/log/nginx/vagrant.com-access.log;
    error_log  /var/log/nginx/vagrant.com-error.log error;

    charset utf-8;

    location / {
        try_files \$uri \$uri/ /app.php?\$query_string /index.php?\$query_string;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    $PHP_WITH_SSL

    # Deny .htaccess file access
    location ~ /\.ht {
        deny all;
    }
}
EOF

# Turn off sendfile to be more compatible with Windows, which can't use NFS
sed -i 's/sendfile on;/sendfile off;/' /etc/nginx/nginx.conf

# Nginx enabling and disabling virtual hosts
curl -L https://gist.githubusercontent.com/fideloper/8261546/raw/ngxen > ngxen
curl -L https://gist.githubusercontent.com/fideloper/8261546/raw/ngxdis > ngxdis
sudo chmod guo+x ngxen ngxdis
sudo mv ngxen ngxdis /usr/local/bin

# Setup the vhost generator script for nginx
# This sould be used for the above setup eventually, rather
# than the hard-coded config above!
curl -L https://gist.githubusercontent.com/fideloper/9063376/raw/ngxhost.sh > ngxvhost
sudo chown root:root ngxvhost
sudo chmod guo+x ngxvhost
sudo mv ngxvhost /usr/local/bin

# Disable "default", enable "vagrant"
sudo ngxdis default
sudo ngxen vagrant

if [[ $PHP_IS_INSTALLED -eq 0 ]]; then
    # PHP Config for Nginx
    sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php5/fpm/php.ini

    sudo service php5-fpm restart
fi

sudo service nginx restart
#/usr/bin/env bash
#测试是否安装了PHP
php-v>/dev/null 2>&1
PHP_是否已安装=$?
echo“>>>安装Nginx”
[[-z“$1”]&&&{echo”!!!未设置IP地址。请检查漫游文件。“退出1;}
如果[-z“$2”];然后
public_folder=“/vagrant”
其他的
public_folder=“$2”
fi
#为最新稳定的nginx添加回购
sudo添加apt存储库-y ppa:nginx/stable
#再次更新
更新源
#安装其余的
sudo apt get安装-y nginx
echo“>>>配置Nginx”
如果[[$PHP_已安装-等式0]];然后

读-d''PHP\u NO\u SSL,看起来非常复杂。如果您想要节点,为什么要使用nginx+php?我建议您从以下内容开始:安装节点并公开端口3000(使用vagant配置中的转发\u端口)。如果这样做有效,您可以安装apache并为您的节点应用程序设置虚拟主机。这太复杂了,但我想尝试保留其中的一些设置,例如为VM设置ip,同时尝试将Nginx用于代理而不是apache。我对Nginx配置是如此的陌生,所以我正在寻找一些修改这个配置的指导。