How to start Nginx after shared folder mounted on VirtualBox

Recently, I set up a new developing environment in a VirtualBox VM. The source code shares between the host and VM by shared folder. It causes a problem that the config file can not be found when Nginx is starting up.

Nginx can not find the specific config file which is in the mounted folder from the host

I searched on Google and found some related posts.

If Nginx does not start after rebooting the server” points out the correct direction of the solution, however, the changes of method 1 mentioned in the article is not working for VirtualBox, and personally, I don’t like the method 2.

While, “How to mount shared folder from VirtualBox at boot time in Debian” describes the mount must happen after vboxadd-service.service started.

Combine this two posts, the solution would be obvious.

Solution

Change the line /etc/systemd/system/multi-user.target.wants/nginx.service in the configuration file of Nginx in VM

After=network.target

Adding vboxadd-service.service

After=network.target vboxadd-service.service

Reboot the VM.

Check Nginx running status with the following command

sudo service nginx status
Nginx started successfully after changes

Solved!

Comments

2 responses to “How to start Nginx after shared folder mounted on VirtualBox”

  1. Leo Avatar
    Leo

    试一下用Docker,那样更简单一些。

  2. mikespook Avatar

    Docker 并不能解决所有的问题啊,其实,我是用 VBox 来跑 Docker 模拟跨物理网络的通讯。

Leave a Reply

Your email address will not be published. Required fields are marked *