Vagrant in the Nginx configuration

Source: Internet
Author: User

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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.