关于vagrant一个虚拟机搭建多个项目配置(总结)

举报
lxw1844912514 发表于 2022/03/27 00:40:24 2022/03/27
【摘要】 问题1:执行vagrant status命令,报错,没有找到命令,翻译;“vargrant bash命令没有找到。” 解答:因为在/home目录中,所有无法执行该命令,需要切换到外部进行执行 问题2:在一个虚拟机中,添加多个项目   lxw.com.conf配置 server { li...

问题1:执行vagrant status命令,报错,没有找到命令,翻译;“vargrant bash命令没有找到。”

解答:因为在/home目录中,所有无法执行该命令,需要切换到外部进行执行

问题2:在一个虚拟机中,添加多个项目

 

lxw.com.conf配置
 

  
  1. server
  2. {
  3. listen 80;
  4. #listen [::]:80;
  5. server_name lxw.com www.lxw.com;
  6. index index.html index.htm index.php default.html default.htm default.php;
  7. root /vagrant/2019bak;
  8. include rewrite/none.conf;
  9. #error_page 404 /404.html;
  10. # Deny access to PHP files in specific directory
  11. #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  12. include enable-php.conf;
  13. location /nginx_status
  14. {
  15. stub_status on;
  16. access_log off;
  17. }
  18. location / {
  19. try_files $uri $uri/ /index.php?$query_string;
  20. }
  21. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  22. {
  23. expires 30d;
  24. }
  25. location ~ .*\.(js|css)?$
  26. {
  27. expires 12h;
  28. }
  29. location ~ /.well-known {
  30. allow all;
  31. }
  32. location ~ /\.
  33. {
  34. deny all;
  35. }
  36. access_log off;
  37. }

 test.com.conf配置文件


  
  1. server
  2. {
  3. listen 80;
  4. #listen [::]:80;
  5. #server_name _;
  6. server_name 192.168.10.250 test.com www.test.com
  7. index index.html index.htm index.php default.html default.htm default.php;
  8. root /vagrant/laizheer/public;
  9. include rewrite/none.conf;
  10. #error_page 404 /404.html;
  11. # Deny access to PHP files in specific directory
  12. #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  13. include enable-php.conf;
  14. location /nginx_status
  15. {
  16. stub_status on;
  17. access_log off;
  18. }
  19. location / {
  20. try_files $uri $uri/ /index.php?$query_string;
  21. }
  22. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  23. {
  24. expires 30d;
  25. }
  26. location ~ .*\.(js|css)?$
  27. {
  28. expires 12h;
  29. }
  30. location ~ /.well-known {
  31. allow all;
  32. }
  33. location ~ /\.
  34. {
  35. deny all;
  36. }
  37. access_log off;
  38. }  

  

 本地host文件配置,“192.168.10.250”需要与Vagrantfile文件中配置的public_network,IP一致,192.168.10.250等同于远程服务器的IP,

Vagrantfile配置


  
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8. # The most common configuration options are documented and commented below.
  9. # For a complete reference, please see the online documentation at
  10. # https://docs.vagrantup.com.
  11. # Every Vagrant development environment requires a box. You can search for
  12. # boxes at https://vagrantcloud.com/search.
  13. config.vm.box = "Centos-7"
  14. # Disable automatic box update checking. If you disable this, then
  15. # boxes will only be checked for updates when the user runs
  16. # `vagrant box outdated`. This is not recommended.
  17. # config.vm.box_check_update = false
  18. # Create a forwarded port mapping which allows access to a specific port
  19. # within the machine from a port on the host machine. In the example below,
  20. # accessing "localhost:8080" will access port 80 on the guest machine.
  21. # NOTE: This will enable public access to the opened port
  22. # config.vm.network "forwarded_port", guest: 80, host: 8080
  23. # Create a forwarded port mapping which allows access to a specific port
  24. # within the machine from a port on the host machine and only allow access
  25. # via 127.0.0.1 to disable public access
  26. # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  27. # Create a private network, which allows host-only access to the machine
  28. # using a specific IP.
  29. # config.vm.network "private_network", ip: "192.168.33.10"
  30. config.vm.network "public_network", ip: "192.168.10.250"
  31. # Create a public network, which generally matched to bridged network.
  32. # Bridged networks make the machine appear as another physical device on
  33. # your network.
  34. # config.vm.network "public_network"
  35. # Share an additional folder to the guest VM. The first argument is
  36. # the path on the host to the actual folder. The second argument is
  37. # the path on the guest to mount the folder. And the optional third
  38. # argument is a set of non-required options.
  39. #config.vm.synced_folder "../www/laizheer", "/home/wwwroot/defalut"
  40. # Provider-specific configuration so you can fine-tune various
  41. # backing providers for Vagrant. These expose provider-specific options.
  42. # Example for VirtualBox:
  43. #
  44. config.vm.provider "virtualbox" do |vb|
  45. # # Display the VirtualBox GUI when booting the machine
  46. vb.gui = false
  47. #
  48. # # Customize the amount of memory on the VM:
  49. vb.memory = "4096"
  50. vb.cpus = "2"
  51. end
  52. #
  53. # View the documentation for the provider you are using for more
  54. # information on available options.
  55. # Enable provisioning with a shell script. Additional provisioners such as
  56. # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  57. # documentation for more information about their specific syntax and use.
  58. # config.vm.provision "shell", inline: <<-SHELL
  59. # apt-get update
  60. # apt-get install -y apache2
  61. # SHELL
  62. end  

 补充:当lxw.com.conf监听端口改变为8080后,访问时对应改变端口  http://lxw.com:8080/

 命令:

sudo vi lxw.com.conf  不用切换到root用户直接使用root的权限

sudo service nginx reload 重启nginx 服务

 

总结:

mac下给vagrant添加多个项目的步骤:

1.修改/usr/local/nginx/conf/nignx.conf,将域名和文件夹目录添加进去

Vagrantfile文件文中项目件夹配置如下

2.修改本地mac中host地址

sudo vi /etc/hosts
 

参考:https://www.jianshu.com/p/752211238c1b

文章来源: blog.csdn.net,作者:lxw1844912514,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/lxw1844912514/article/details/100029126

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。