What
本篇主要是基于Nginx在Mac上搭建自己的服务器。我相信很多朋友肯定是第一次听到Nginx,关于它具有怎样的传奇,这儿肯定说不完也说不透.有兴趣的朋友可以自行google或者baidu.
Why
为什么要搭建自己的服务器呢。 好处肯定多多,这儿说一条——模拟数据。很多时候,我们在前端开发的过程中,API接口没有做好.当我们要铺界面时,如果等待API的开发完成,无疑是件很耽误工作的事情。还有一点,即使API完成了,我们开发完项目时,需要自测各种极限的数据。例如
- 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
复杂来说,这是件很难的事情,因为无论是Nginx,还是它所需要的准备工作,都是一个个庞然大物。搞不懂!你需要安装Nginx,你可以自己独立装,也可以用别的包安装. 后者那推荐的是Homebrew.这也是下面我带大家一起来做的。 如果是前者,不要问我,我装了一下午,然后失败了。简单来说,跟着我来做,几个步骤,几分钟,带你实现。
platform: Mac 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:
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
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.
Welcome to Nginx is written on the screen.
If the following screen is unable to connect to the server, turn head up three bows, 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
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
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 into the last side of the line.
Server {Listen8080; server_name localhost; #access_log logs/Host.access.log Main; Location~*{add_header Content-type"Application/json"; root HTML; if(!-F $request _filename) {Rewrite^/(.*) /$1. JSON last; } index index.php index.html index.htm; } error_page405= $http//$host $request_uri; }
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
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
sudo cp/usr/local/opt/nginx/*. plist /library/launchdaemons
Can.
Transferred from: http://blog.csdn.net/qq_22383951/article/details/53019034
If you have any questions, you can contact my email address [email protected]
Mac teaches you how to build your own server on a Mac--nginx