Skip to content

Instantly share code, notes, and snippets.

@zedar
Created July 16, 2014 12:22
Show Gist options
  • Save zedar/bc4ac6802f96b4ea4b4b to your computer and use it in GitHub Desktop.
Save zedar/bc4ac6802f96b4ea4b4b to your computer and use it in GitHub Desktop.
Vagrant and nginx as proxy configuration
## Install vagrant:
* install virtualbox
* install vagrant
## Configure vagrant
$ mkdir vagrant
$ cd vagrant
or
C:\> mkdir vagrant
C:\> cd vagrant
Add default vagrant box with ubuntu inside
$ vagrant box add hashicorp/precise32
Add configuration to Vagrantfile
$ vim Vagrantfile
Set precise32 as default box. Set port forwarding from 5000 (localhost:5000) to 80 on the guest machine (vargant).
> Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise32"
config.vm.network "forwarded_port", host: 5000, guest: 80
end
Start vagrant machine:
$ vagrant up
Check vargant status
$ vagrant status
Reload vargant configuration
$ vagrant reload
Stop vagrant
$ vagrant halt
Login to vagrant machine
$ vagrant ssh
Update ubuntu. From inside vagrant machine
$ sudo apt-get update
Install vim
$ audo apt-get install vim
Install nginx
$ sudo apt-get install nginx
## nginx configuration
Remove sites-enabled from nginx configuration
$ sudo vim /etc/nginx/nginx.conf
Comment line:
> # include /etc/nginx/sites-enabled/*;
Add new configuration file
$ sudo vim /etc/nginx/conf.d/myproxy.conf
There are 2 main mappings. One is in vagrant (mapping of ports 5000 => 80) and the other is in nginx inside vagrant box.
Proxy calls google but keeps path in the browser.
Content of myproxy.conf:
> server {
listen 80;
server_name localhost;
# remove all parameters
location /my/proxy/ {
rewrite ^/my/proxy/(.*)$ /
}
location / {
proxy_pass https://www.google.pl;
proxy_redirect default;
proxy_read_timeout 60s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment