Nginx configuration in Vagrant

Source: Internet
Author: User
: 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 sshCommand 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:8080Orwww.test.com:8080You 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.

    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.