In the series article 1 and series article 2 articles, the installation of vagrant and the automatic installation of the development environment software are described.
This article will write about the configuration of Nginx in the virtual machine and how to access Nginx in the real machine.
Open the Vagrantfile file and locate the following configuration:
config.vm.network"forwarded_port"808080
This configuration means that the 80 port of the virtual machine is mapped to the 8080 port of the real machine.
Using vagrant ssh
commands to enter a virtual machine
Backing up the default Nginx configuration file
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back
Modify Configuration
Open /etc/nginx/nginx.conf
, change the contents of the content as follows:
events { 1024;}http { server { 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 500502503504 /50x.html; location = /50x.html { root /projects/; } }}
Add HTML page
In the virtual machine:cd /projects
Create a new index.html or index.htm file in this directory with the following contents:
<html><head><title>R_Lanffy
title>
head><body> Hello World
body>
html>
Access test
Enter the address in the real-world browser: test.com:8080
or www.test.com:8080
You can access the Nginx-related configuration in the virtual machine.
If you want to reach the input test.com, you need to change the Vagrantfile file to 8080 to 80.
Note: If there is a situation that cannot be accessed, it is likely that port 8080 is occupied before the virtual machine is started. The workaround is to modify the port to a port that is not occupied.
To see if the port is listening: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); }); });
The above describes the vagrant in the Nginx configuration, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.