Teach you how to build your own server on a Mac--nginx

Source: Internet
Author: User

Tag: Write target allows IP address nsstring src. NET complete rar

Original address: 53019034

What
    1. This article is mainly based on Nginx on the Mac to build their own server.
    2. I believe a lot of friends must be the first time to hear Nginx, about its legend, there must be no end to say.
    3. Interested friends can self-Google or Baidu.
Why
    1. Why build your own server?
    2. There's a lot of benefits, and here's one--simulation data.
    3. Many times, in the process of front-end development, the API interface is not doing well.
    4. When we want to lay out the interface, if we wait for the development of API, it is no doubt that the work is very delayed.
    5. Also, even if the API is complete, we need to self-test the various limits of data when we have finished developing the project. For example
    • Agreed to return is NSString, if the return is NSNumber, you will collapse it?
    • A well-appointed field has a return value and suddenly returns to NULL, will you collapse?
    • The assignment text on the agreed label is a maximum of 7 words and suddenly gives you 77 words, will you become ugly?

      Someone asked, isn't it a pact?
      The word API is also human development, you write the client will also crash it, will not allow others backstage error???
      What a reason, Big Brother!

How
    1. Complicated, this is a difficult thing, because either nginx, or it needs to prepare the work, are a monster. I don't understand!
    2. You need to install Nginx, you can install it yourself, or you can use another package.
    3. The latter is recommended by homebrew. That's what I'm going to do with you.
    4. If it is the former, do not ask me, I installed an afternoon, and then failed.
    5. Simply put, follow me to do, a few steps, a few minutes, bring you to realize.

    1. Platform: Mac
    2. System: 10.11.1

1. Installing homebrew

2. Installing Nginx

3. Start Nginx

4. Configure the JSON file

5. Configure Nginx

6. Show Results

1. Installing homebrew

Open Terminal, enter:

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

Follow the steps to go. The terminal has a hint.

2. Rely on homebrew to install Nginx

Still in the terminal

brew install nginx

This wait time will be longer. If you look closely at the process of the terminal. You will find how smart you are to install with homebrew. In fact, before installing Nginx also to help you install a lot of other, if you install independently, is very laborious ...

3. Start Nginx

Still in the terminal, enter

nginx

Just enter the line. Don't be surprised, it's so simple.
How to verify that the nginx can be used. You entered in the browser, enter, the localhost:8080 following screen appears, indicating success.

If it is the following screen, turn head up three bow, and then come back to see where the error.

4. Configure the JSON file

That configuration file is in

/usr/local/Cellar/nginx/1.8.0/html/

This directory will default to two files of 50x.html and index.html. You add a new JSON file, take a name called Oscar.json, in which you can write some dictionary array, save.

5. Configure Nginx

After the installation is complete, the default path is

/usr/local/etc/

This file will have an Nginx folder and a OpenSSL folder.
Click Open Nginx folder, there will be a

nginx.conf.default



Document, remember, do not look wrong, the name is very similar. Open with a text editor, there is content in the default, you can see. Paste the following in.

    1. server {
    2. Listen 8080;
    3. server_name localhost;
    4. #access_log Logs/host.access.log Main;
    5. Location ~* {
    6. Add_header content-type "Application/json";
    7. root HTML;
    8. if (!-f $request _filename) {
    9. Rewrite ^/(. *)/$1.json last;
    10. }
    11. Index index.php index.html index.htm;
    12. }
    13. Error_page 405 =200 http:/$host $request_uri;
    14. }

6. Show Results
If your newly added JSON file is called Oscar.json, the directory is just saying

/usr/local/Cellar/nginx/1.8.0/html/oscar.json

So you're typing in the browser.

localhost:8080/oscar.json



Let's see what you've achieved!

If your page has a JSON file that you have configured, then congratulations. If someone wants to access your resources, make sure you are in the same LAN, then replace your IP address with localhost, and then look at the page of your friend's computer.

MAC System on startup Nginx

After installing install via brew

      1. sudo cp/usr/local/opt/nginx/*.plist/library/launchdaemons
      2. sudo launchctl load-w/library/launchdaemons/homebrew.mxcl.nginx.plist

Teach you how to build your own server on a Mac--nginx

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.