G
G
Greg Popov2016-07-31 21:02:25
Nginx
Greg Popov, 2016-07-31 21:02:25

How to migrate Yii2 from two domains to one NGINX?

Zadolbalsya already to the very ears.
Deployed Vagrant, which came to me along with yii2-advanced when installed via composer.
Problems persist: trying to do everything on one domain (classic), domain.dev && domain.dev/admin
Here is Vagrant

require 'yaml'
require 'fileutils'

domains = {
  frontend: 'fabidab.dev',
  backend:  'admin.fabidab.dev'
}

config = {
  local: './vagrant/config/vagrant-local.yml',
  example: './vagrant/config/vagrant-local.example.yml'
}

# copy config from example if local config not exists
FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
# read config
options = YAML.load_file config[:local]

# check github token
if options['github_token'].nil? || options['github_token'].to_s.length != 40
  puts "You must place REAL GitHub token into configuration:\n/yii2-app-advancded/vagrant/config/vagrant-local.yml"
  exit
end

# vagrant configurate
Vagrant.configure(2) do |config|
  # select the box
  config.vm.box = 'ubuntu/trusty64'

  # should we ask about box updates?
  config.vm.box_check_update = options['box_check_update']

  config.vm.provider 'virtualbox' do |vb|
    # machine cpus count
    vb.cpus = options['cpus']
    # machine memory size
    vb.memory = options['memory']
    # machine name (for VirtualBox UI)
    vb.name = options['machine_name']
  end

  # machine name (for vagrant console)
  config.vm.define options['machine_name']

  # machine name (for guest machine console)
  config.vm.hostname = options['machine_name']

  # network settings
  config.vm.network 'private_network', ip: options['ip']

  # sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
  config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'

  # disable folder '/vagrant' (guest machine)
  config.vm.synced_folder '.', '/vagrant', disabled: true

  # hosts settings (host machine)
  config.vm.provision :hostmanager
  config.hostmanager.enabled            = true
  config.hostmanager.manage_host        = true
  config.hostmanager.ignore_private_ip  = false
  config.hostmanager.include_offline    = true
  config.hostmanager.aliases            = domains.values

  # provisioners
  config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']]
  config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false
  config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always'

  # post-install message (vagrant console)
  config.vm.post_up_message = "Frontend URL: http://#{domains[:frontend]}\nBackend URL: http://#{domains[:backend]}"
end

Here is the current NGINX configuration:
server {
   charset utf-8;
   client_max_body_size 128M;

   listen 80; ## listen for ipv4
   #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

   server_name fabidab.dev;
   root        /app/frontend/web/;
   index       index.php;

   access_log  /app/vagrant/nginx/log/frontend-access.log;
   error_log   /app/vagrant/nginx/log/frontend-error.log;

   location / {
       # Redirect everything that isn't a real file to index.php
       try_files $uri $uri/ /index.php$is_args$args;
   }

   # uncomment to avoid processing of calls to non-existing static files by Yii
   #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
   #    try_files $uri =404;
   #}
   #error_page 404 /404.html;

   location ~ \.php$ {
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       #fastcgi_pass   127.0.0.1:9000;
       fastcgi_pass unix:/var/run/php5-fpm.sock;
       try_files $uri =404;
   }

   location ~ /\.(ht|svn|git) {
       deny all;
   }
}

server {
   charset utf-8;
   client_max_body_size 128M;

   listen 80; ## listen for ipv4
   #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

   server_name admin.fabidab.dev;
   root        /app/backend/web/;
   index       index.php;

   access_log  /app/vagrant/nginx/log/backend-access.log;
   error_log   /app/vagrant/nginx/log/backend-error.log;

   location / {
       # Redirect everything that isn't a real file to index.php
       try_files $uri $uri/ /index.php$is_args$args;
   }

   # uncomment to avoid processing of calls to non-existing static files by Yii
   #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
   #    try_files $uri =404;
   #}
   #error_page 404 /404.html;

   location ~ \.php$ {
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       #fastcgi_pass   127.0.0.1:9000;
       fastcgi_pass unix:/var/run/php5-fpm.sock;
       try_files $uri =404;
   }

   location ~ /\.(ht|svn|git) {
       deny all;
   }
}

Found this solution. Nothing works. Help already, I'm not even a novice system administrator, for me it's a dark forest...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LAV45, 2016-08-01
@LAV45

Try looking here https://github.com/LAV45/yii2-translated-behavior-demo
https://yii2-translated-behavior.herokuapp.com/
https://yii2-translated-behavior.herokuapp.com/admin ( admin:admin)
https://github.com/LAV45/yii2-translated-behavior-...
https://github.com/LAV45/yii2-translated-behavior-...
https://github.com/ LAV45/yii2-translated-behavior-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question