Nginx

無法從 Vagrant 主機與 nginx 通信

  • October 10, 2013

我正在使用 Ansible 在 Vagrant 框中編譯和配置 Nginx。

如果我curl http://localhost/從盒子裡面跑,我會得到預期的響應(phpinfo())。

http://testapp:8080/如果我從我的 Mac 主機訪問 URL ,那麼我將無法連接。

我的配置如下:

主機:/etc/hosts

192.168.100.10 testapp

主機:流浪文件

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

 config.vm.define "web" do |web_config|
   web_config.vm.box = "raring64"
   web_config.vm.box_url = "https://dl.dropboxusercontent.com/s/{{redacted}}/raring64.box"
   web_config.vm.network "forwarded_port", guest: 80, host: 8080
   web_config.vm.network "private_network", ip: "192.168.100.10"

   web_config.vm.provision :ansible do |ansible|
     ansible.playbook = "devops/webserver.yml"
     ansible.hosts = "webservers"
     ansible.inventory_file = "devops/hosts"
     ansible.verbosity = "vv"
     ansible.verbose = "true"
   end

   web_config.vm.provider "virtualbox" do |v|
     v.customize ["modifyvm", :id, "--memory", "256"]
   end
 end
end

來賓:/etc/nginx-1.5.6/nginx.conf

user www-data www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
 worker_connections  768;
 multi_accept on;
}

http {

 include       /etc/nginx-1.5.6/mime.types;
 default_type  application/octet-stream;

 access_log    /var/log/nginx/access.log;

 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;

 keepalive_timeout  65;

 server_tokens off;

 gzip  off;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_proxied any;
 gzip_vary off;
 gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
 gzip_min_length  1000;
 gzip_disable     "MSIE [1-6]\.";

 include /etc/nginx-1.5.6/sites-enabled/*;
}

來賓:/etc/nginx-1.5.6/sites-enabled/testapp.conf

upstream phpbackend {
   server unix:/var/run/php-fpm-www.sock;
}

server {
   server_name  testapp;
   listen 0.0.0.0:80;
   root  /web/testapp/public;
   index index.php;

   access_log  /var/log/nginx/webvg.access.log;
   error_log /var/log/nginx/webvg.error.log debug;

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

   location ~ \.php$ {
       fastcgi_pass phpbackend;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME /web/testapp/public/$fastcgi_script_name;
       include fastcgi_params;
       fastcgi_param CACHE_HOST 127.0.0.1;
       fastcgi_param CACHE_PORT 6379;
       fastcgi_param NEO_HOST   127.0.0.1;
       fastcgi_param NEO_PORT   7474;
       fastcgi_param SERVER_ENV dev;
   }

   location ~ ^/(php_status|php_ping)$ {
       fastcgi_pass phpbackend;
       fastcgi_param SCRIPT_FILENAME /web/testapp/public/$fastcgi_script_name;
       include fastcgi_params;
       allow 127.0.0.1;
       deny all;
   }

   location /nginx_status {
       allow 127.0.0.1;
       deny all;
       access_log off;
   }

   location ~ /\.git {
       deny all;
   }
}

誰能發現我遺漏的明顯東西?

非常感謝

因此,我編輯了 /etc/hosts 文件以指向127.0.0.1而不是 vagrantfile 中定義的地址,現在我可以從主機訪問該網站。

我可能要瘋了,但我認為您的應用程序確實處於打開狀態http://192.168.100.10:80(並且應該從主機和來賓,或testapp.com:80單獨從主機執行)而不是埠 8080。

8080 引用是指從 mac 主機轉發的埠,localhost:8080它應該192.168.100.10:80在客戶機上指向該埠。

引用自:https://serverfault.com/questions/544846