: This article mainly introduces Nginx configuration in Vagrant. if you are interested in the PHP Tutorial, refer to it.
In Articles 1 and 2, we introduced the installation of Vagrant and the automatic installation of software in the development environment.
This article describes how to configure Nginx in a virtual machine and how to access Nginx on a real machine.
Open the Vagrantfile file and find the following configuration:
config.vm.network"forwarded_port", guest: 80, host: 8080
This configuration maps port 80 of the virtual machine to port 8080 of the real machine.
Usevagrant ssh
Command to enter the virtual machine
Back up the default nginx configuration file
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back
Modify configurations
Open/etc/nginx/nginx.conf
, Change the content as follows:
events { worker_connections 1024;}http { server { listen 80; server_name test.com www.test.com; charset utf-8; location / { root /projects/; index index.html index.htm; } #redirect server error pages to the static page /50x.html error_page 500502503504 /50x.html; location = /50x.html { root /projects/; } }}
Add HTML page
In a virtual machine:cd /projects
Create the index.html#index.htm file in the directory as follows:
R_Lanffy Hello World
Access test
Enter the address in the real machine browser:test.com:8080
Orwww.test.com:8080
You can access nginx configurations in the virtual machine.
If you want to access test.com, you need to change 8080 in the Vagrantfile file to 80.
Note: If access is unavailable, it is likely that port 8080 is occupied before the VM is started. The solution is to change the port to an unused port.
Check whether the port is listened on:netstat -an | grep 8080
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the Nginx configuration in Vagrant, including some content, and hope to be helpful to friends who are interested in PHP tutorials.