ãã¼ã«ã«ç°å¢ã§Vagrant+nginxã§æ°è»½ã«ãªãã¼ã¹ãããã·ãã
ãµã¼ãã¼ãµã¤ãã®ã¢ããªã±ã¼ã·ã§ã³ããã£ã¦ãéçã³ã³ãã³ãã ãHTTPãµã¼ãã¼ã§é ä¿¡ãããã£ã¦ããã¦ã¼ã¹ã±ã¼ã¹ãããã¨æãã¾ãã
ãµã¼ãã¼ä¸ã§åããå ´åã«ã¯ã ããããããªæãã«HTTPãµã¼ãã¼ã§ãªãã¼ã¹ãããã·ãã¦ã¢ããªã±ã¼ã·ã§ã³ã¨éçã³ã³ãã³ããæ¯ãåãã¾ãããã
ããããããããã¼ã«ã«ã®éçºç°å¢ã®ã¨ãã¯ã©ãããï¼ã£ã¦ãã話ã§ãã
ãã¼ã«ã«ç°å¢ã®ãã¹ãOSã«ã¯HTTPãµã¼ãã¼ã¯ãã¦ãããªã
ãã¼ã«ã«ç°å¢ã§åããã¨ããã«ã¯ãåãããã«HTTPãµã¼ãã¼ããã¦ãã°ãããã§ãããè¤æ°ã®ããã¸ã§ã¯ãããããã¡ãªããããããã¦ãã¨ããç¨ã®virtualhostãæ¸ããããhostsã§ãã¹ãåãæ¸ããããã¦ãªããããµãæãã«ãªã£ã¦ãã¾ãã¾ãããã¨ã¯ãè¤æ°äººã§éçºãªããããã¨ãWindowsã®äººãããã°ãMacã®äººãããããåèªè²ã ãªããã¸ã§ã¯ããã£ã¦ããã§ããã£ã¡ã§ã¯åããã©ããã£ã¡ã§ã¯åããªãã¨ãå«ãªæãã«ãªãã¾ãã
ããã§ãVagrantã§HTTPãµã¼ãã¼ãã¦ã¦æ¯ãåããããªãããªã¨æã£ã¦è©¦ãã¦ã¿ã¾ããã
ãã®å³ã®å·¦å´ã¿ããã«ãXAMPPã¨ãã§ãã¹ãå´ã«HTTPãµã¼ãã¼ãã¦ãããããªããå³å´ã¿ããã«Vagrantã使ã£ã¦ãã¹ãå´ã¯ããããªã¾ã¾ã«ãã¦ããããã£ã¦ããæ°æã¡ã§ãããã®ããã¸ã§ã¯ããéçºãããªãããã®Vagrantãupããã ãã¿ããã«ãããï¼
å³å´ã®Vagrantã使ã£ããã¤ã®èª¬æãããã¨ã
- Vagrantã§ç«ã¦ãä»®æ³ãµã¼ãã¼å ã«Nginxãå ¥ã£ã¦ã¦Nginxã¯80çªãã¼ãã§å¾ ã¡åãã
- ä»®æ³ãµã¼ãã¼ã¯ãã¼ããã©ã¯ã¼ãã£ã³ã°ã§ãã¹ãã®8000çªãã¼ããã²ã¹ãã®nginxã®80çªãã¼ãã«è»¢é
- ä»®æ³ãµã¼ãã¼ã¯Vagrantã®å ±æãã¡ã¤ã«æ©è½ã使ã£ã¦ããã¹ãå´ã®éçã³ã³ãã³ããNginxã«é ä¿¡ããã
- ãã¹ãå´ã§ãµã¼ãã¼ã¢ããªã±ã¼ã·ã§ã³ãèµ·åï¼ãã®å³ã®å ´åã¯Javaã§9000çªãã¼ãã§èµ·åï¼
- Nginxã¯éçãã¡ã¤ã«ä»¥å¤ã®ãªã¯ã¨ã¹ããªããã¹ãã®Javaã¢ããªã±ã¼ã·ã§ã³ã«ãªãã¼ã¹ãããã·ãã
ããã§ããã©ã¦ã¶ããã¯ãhttp://localhost:8000/
ã§ã¢ã¯ã»ã¹ããã°ããã¹ãå´ã®ãµã¼ãã¼ã¢ããªã±ã¼ã·ã§ã³ã«ã¤ãªããããéçã³ã³ãã³ãã¯ãã®ã¾ã¾é
ä¿¡ãããã¨ããæãã
ããããããªããJavaã®ã¢ããªã±ã¼ã·ã§ã³ãä»®æ³ãã·ã³ä¸ã§åããã¡ããã°ï¼ã£ã¦ãã¨ã«ãªããã ãããã©ãä»®æ³ãã·ã³ã«ããã¾ãã¡ã¢ãªã¨ãå²ãå½ã¦ãããªããããã¹ãå´ã®CPUã¨ãã¡ã¢ãªã使ããããªã£ã¦æã£ãã®ã§ãããã¾ããã
ã¨ãããã¨ã§ãå®éã«æ¸ããè¨å®ãã¡ã¤ã«ã®èª¬æããã¦ããã¾ãã
Vagrantfile
CentOS6.5ã§initãããchef/centos-6.5
vagrant init chef/centos-6.5
Vagrantfileãã§ããã®ã§ãè¨å®ãæ¸ãæãã¾ãã
ãã¼ããã©ã¯ã¼ãã£ã³ã°ã®è¨å®ã¨ãéçã³ã³ãã³ããå
±æãã©ã«ãã¨ãã¦ã/var/www/html/
ã«ããããããã¸ã§ãã³ã°ã¯chefåãããªãã®ã§ã·ã§ã«ã§ããï¼chefåå¼·ããªãã¨ããï¼
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "chef/centos-6.5" # 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: 8000 # 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 "/path/to/your/static/resources/", "/var/www/html" config.vm.provision "shell", path: "provision.sh" end
provision.sh
次ã«ããããã¸ã§ãã³ã°ããshã®å
容ã§ãã
nginxã¤ã³ã¹ãã¼ã«ãã¦ããã¼ã«ã«ç°å¢ã ããã¨ããããããã¡ã¤ã¢ã¦ã©ã¼ã«åãã
function install_nginx() { rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm yum -y install nginx cp -f /vagrant/default.conf /etc/nginx/conf.d/default.conf service nginx start chkconfig nginx on } function stop_iptables() { service iptables stop chkconfig iptables off } install_nginx stop_iptables
default.conf (nginx)
nginxã®è¨å®ãã¡ã¤ã«ã¯ãã®ãããã¸ã§ãã³ã°ã®æã«ãcp -f /vagrant/default.conf /etc/nginx/conf.d/default.conf
ã¨ããæãã§ãã®Vagrantfileãç½®ãã¦ããå ´æã«confãç¨æãã¨ãã¦ä¸æ¸ãããã
ããã§ãã¡ãã£ã¨ä¸å·¥å¤«ããã£ã¦ãVagrantã§ä½ã£ãä»®æ³ãµã¼ãã¼ã®ããã©ã«ãã²ã¼ãã¦ã§ã¤ã¯å¿
ãã10.0.2.2
ã«ãªããããªã®ã§ããªãã¼ã¹ãããã·å
ã¯ã10.0.2.2
ã¨ãã¨ãããã¨ãrootã¯ãå
±æãã©ã«ãã¨ãã¦ããã/var/www/html/
ã
proxy_buffering off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_http_version 1.1; upstream playframework { server 10.0.2.2:9000; } server { listen 80; server_name localhost; root /var/www/html; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { if (-f $request_filename) { break; } proxy_pass http://playframework; proxy_redirect default; } #error_page 404 /404.html; // 以ä¸çç¥
ããã§ããã¹ãå´ã®ãã©ã¦ã¶ãããhttp://localhost:8000/
ã£ã¦ã¢ã¯ã»ã¹ããã°ããã¹ãå´ã®Javaã¢ããªã±ã¼ã·ã§ã³ã«ã¤ãªãã£ã¦ãéçãã¡ã¤ã«ãåå¨ããã°ãéçãã¡ã¤ã«ãé
ä¿¡ããã¾ãã
ã¾ã¨ã
ããã§ããã¹ãå´ã®hostsã¨ãæ¸ãæããªãã¦ãæ°è»½ã«ãªãã¼ã¹ãããã·ããã¦ããã¾ããï¼
å人çã«ãã®Vagrant+nginxæ¹å¼ã®ããã¨ããã¯ãã£ã¨ãã£ã¦ãå
¨ã¦ã®è¨å®ãã¡ã¤ã«ãã½ã¼ã¹ç®¡çã«ã³ãããã§ãããã¨ã§ããããããVagrantã§ä½è¨ãªãã©ã°ã¤ã³ãå
¥ãã¦ãªããããWindowsã ããããMacã ããããOSã®Rubyã®ãã¼ã¸ã§ã³ããªãã§ãããã¨ããªããªãOSã«Rubyãå
¥ã£ã¦ãªããããã¿ããªåãããã«åãã¨ãããã¨ã¦ãããã¨æã£ã¦ã¾ãã