Search code examples
http-redirectnginxvagrantvirtualboxhttp-status-code-301

nginx on vagrant keeps on dropping port


so I have vagrant with port forwarding

here is vagrantfile

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

  config.vm.provider "virtualbox" do |v|
        v.memory = 2048
        v.cpus = 4
  end

  config.berkshelf.enabled = true
  config.berkshelf.berksfile_path = "./Berksfile"
  config.omnibus.chef_version = :latest

  config.vm.network :forwarded_port, guest: 80, host: 8080
  config.vm.network :forwarded_port, guest: 22, host: 2020

end

Here is nginx.conf

user www-data;
worker_processes  4;

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

events {
  worker_connections  1024;
}

http {

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


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

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_requests 100;
  keepalive_timeout  65;


  gzip  on;
  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/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;
  gzip_min_length  1000;
  gzip_disable     "MSIE [1-6]\.";


  variables_hash_max_size 1024;
  variables_hash_bucket_size 64;
  server_names_hash_bucket_size 64;
  types_hash_max_size 2048;
  types_hash_bucket_size 64;



  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

here is sites_enabled/default

server {
  listen   80;
  server_name  precise64;

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

  root   /vagrant/site/www/public;
  index  index.php index.html index.htm;

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

  location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    fastcgi_index index.php;
  }
}

The issue is that everytime I go to http://localhost:8080/somedirectory on my browser, nginx ends up redirecting (301) to http://localhost/somedirectory

If I access a specific file, it doesn't do the redirect as expected

why is that happening and how can I prevent nginx from dropping the port?


Solution

  • I don't see a redirect in your NGINX config so my guess is that it's coming from your PHP app.