Home > Backend Development > PHP Tutorial > Nginx configuration in Vagrant

Nginx configuration in Vagrant

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:14:11
Original
1529 people have browsed it

Nginx configuration in Vagrant

In series of articles 1 and 2, we introduced the installation of Vagrant and the automatic installation of development environment software.

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 find the following configuration:

<code>config<span>.vm</span><span>.network</span><span>"forwarded_port"</span>, guest: <span>80</span>, host: <span>8080</span></code>
Copy after login

This configuration means to map port 80 of the virtual machine to port 8080 of the real machine.

Use the vagrant ssh command to enter the virtual machine

Back up the default nginx configuration file

<code>sudo <span>cp</span> /etc/nginx/nginx<span>.conf</span> /etc/nginx/nginx<span>.conf</span><span>.back</span></code>
Copy after login

Modify the configuration

Open /etc/nginx/nginx.conf and change the content inside as follows:

<code>events {
    worker_connections <span>1024</span><span>;</span>
}

http {
    server {
        listen <span>80</span><span>;</span>
        server_name test<span>.com</span> www<span>.test</span><span>.com</span><span>;</span>
        charset utf-<span>8</span><span>;</span>        location / {
            root /projects/<span>;</span>
            index index<span>.html</span> index<span>.htm</span><span>;</span>
        }

        <span>#redirect server error pages to the static page /50x.html</span>
        error_page <span>500</span><span>502</span><span>503</span><span>504</span> /<span>50</span><span>x</span><span>.html</span><span>;</span>
        location = /<span>50</span><span>x</span><span>.html</span> {
            root /projects/<span>;</span>
        }
    }

}</code>
Copy after login

Add an HTML page

In the virtual machine: cd /projects

Create a new index.html or index.htm file in this directory with the following content:

<code><span>html</span>><span>head</span>><span>title</span>>R_Lanffy<span><span>title</span>></span><span><span>head</span>></span><span>body</span>>
        Hello World
    <span><span>body</span>></span><span><span>html</span>></span></code>
Copy after login

Access test

Enter the address in the real machine browser: test. com:8080 or www.test.com:8080 to access the nginx related configuration in the virtual machine.

If you want to achieve the purpose of accessing test.com, you need to change the 8080 in the Vagrantfile file to 80

Note: If access is not possible, it is most likely that the 8080 port is before starting the virtual machine. occupied. The solution is to change the port to an unoccupied port.

Check whether the port is being monitored: netstat -an | grep 8080

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the Nginx configuration in Vagrant, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Error restarting nginx
From 1970-01-01 08:00:00
0
0
0
server - Nginx configuration webapp problem
From 1970-01-01 08:00:00
0
0
0
Nginx default.conf problem
From 1970-01-01 08:00:00
0
0
0
centos7 - NGINX exception occurs
From 1970-01-01 08:00:00
0
0
0
nginx load balancing
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template