Article From:https://www.cnblogs.com/liuhan0727/p/9970878.html

 

 

 

1、Open terminal

2、Install Command Line tools

xcode-select --install

3、Install the brew command

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

4、Install nginx

1
brew install nginx

5、start nginx

1
sudo nginx

 

OK, nginxIt’s installed and accessible in browser. The default port is 8080.

Enter http://localhost:8080/in the browser to see the server nginx built on the computer

8080It is the port of default website settings that nginx comes with.

Now let’s create a website for ourselves, set up ports and map paths

6、Custom Web Sites and Ports

6.1 Create a website and write several test pages

6.2  Copy the physical path of the TanWeb folder, open the terminal, and prepare to edit the configuration file of nginx:

vim /usr/local/etc/nginx/nginx.conf

6.3 After entering the nginx.conf page, press the “i” key to enter the editing state.

     Customize the port and configure the local website TanWeb, pay attention to setting access rights (user root owner;), otherwise you will have 403 errors when visiting the site.

6.4  Press ESC key to exit editing status, enter: wq, save exit nginx.conf page

6.5  Restart nginx

sudo nginx -s reload

6.6 By typing localhost into the browser and adding custom ports, you can access the configured website.

     For example, if my port is configured as 5188, enter http://localhost:5188/ in the browser, as shown in the figure.

 

In addition, if you do not want to edit nginx.conf through the terminal, you can directly go to the nginx folder to open the configuration file for editing and saving.

 

Leave a Reply

Your email address will not be published. Required fields are marked *