Install nginx on mac, and modify the configuration file

 
1. Install Homebrew
The following command input terminal
> ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 

After about a few minutes later to complete the installation, during which prompted for a password, enter your Mac password, after a successful installation you can install nginx

 

2. Install nginx
Enter the following command terminal
> brew install nginx

 

3. Verify that the installation was successful
Enter the following command terminal
> sudo nginx

 

Browser input
> http://localhost:8089

 

Page display welcome to nginx! Says the installation was successful.

 

4. Locate nginx installation directory, usually installed in usr / local / Cellar / nginx / version / bin. You can also go to Find command
```
MacdeMacBook-Pro-3: Desktop zhongbaihua $ cd / usr
MacdeMacBook-Pro-3: usr zhongbaihua $ ls
bin lib local share
include libexec sbin standalone
MacdeMacBook-Pro-3: usr zhongbaihua $ cd local
MacdeMacBook-Pro-3: local zhongbaihua $ ls
Caskroom Homebrew git opt ​​var
Cellar bin include sbin
Frameworks etc lib share
MacdeMacBook-Pro-3:local zhongbaihua$ cd Cellar
MacdeMacBook-Pro-3:Cellar zhongbaihua$ ls
nginx [email protected] pcre
MacdeMacBook-Pro-3:Cellar zhongbaihua$ cd nginx
MacdeMacBook-Pro-3: nginx zhongbaihua $ ls
1.17.6
MacdeMacBook-Pro-3: nginx zhongbaihua $ cd 1.17.6
MacdeMacBook-Pro-3: 1.17.6 zhongbaihua $ ls
CHANGES bin
INSTALL_RECEIPT.json homebrew.mxcl.nginx.plist
LICENSE html
README share
MacdeMacBook-Pro-3: 1.17.6 zhongbaihua $ cd bin
MacdeMacBook-Pro-3: bin zhongbaihua $ ls
nginx
MacdeMacBook-Pro-3: bin zhongbaihua $ pwd
/usr/local/Cellar/nginx/1.17.6/bin
MacdeMacBook-Pro-3: bin zhongbaihua $

 

Find --------- --------- or by a more simple way

 

MacdeMacBook-Pro-3:bin zhongbaihua$ which nginx
/usr/local/bin/nginx
MacdeMacBook-Pro-3:bin zhongbaihua$ ls -alF /usr/local/bin/nginx
lrwxr-xr-x 1 zhongbaihua admin 32 12 24 23:03 /usr/local/bin/nginx@ -> ../Cellar/nginx/1.17.6/bin/nginx
MacdeMacBook-Pro-3: bin zhongbaihua $

 

```
5. Modify nginx configuration, enter the command to begin the terminal configuration file editing nginx
> vim /usr/local/etc/nginx/nginx.conf

 

```
#user zhongbaihua owner;
worker_processes 1;

 

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log logs/error.log info;

 

#pid logs/nginx.pid;



events {
worker_connections 1024;
}



http {
include mime.types;
default_type application/octet-stream;

 

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

 

#access_log logs/access.log main;

 

sendfile on;
#tcp_nopush on;

 

#keepalive_timeout 0;
keepalive_timeout 65;

 

#gzip on;

 

server {
charset utf-8;
listen 8089;
server_name http_host;
root /Users/zhongbaihua/upload/;
auto index is;
add_header Cache-Control "no-cache, must-revalidate";
location / {
add_header Access-Control-Allow-Origin *;
}
}

 

server {
listen 8080;
server_name localhost;

 

#charset koi8-r;

 

#access_log logs/host.access.log main;

 

location / {
root html;
index index.html index.htm;
}

 

#error_page 404 /404.html;

 

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

 

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

 

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}



# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

 

# location / {
# root html;
# index index.html index.htm;
# }
#}



# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

 

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

 

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

 

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

 

# location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
include /Users/zhongbaihua/upload/upload.conf;
}

 

```
> At this point you enter the edit mode nginx.conf file, press the keyboard i can edit.

 

> At the bottom to add files include /Users/zhongbaihua/upload/upload.conf; mean adding a nginx configuration path, equivalent to the contents of the target file is added to the nginx.conf content.

 

> Beginning of the file #user zhongbaihua owner; add your current login mac user name, as well as space owner.

 

> After modification, press esc pieces Input: wq enter, which means to save and exit. :! Q enter, save and exit is not

 

6. nginx configuration changed. Your users / username / directory New Folder New upload.conf upload files.

 

> 1. Terminal cd / users / user name. mkdir upload, create a new folder. 1.1 cd upload, just enter the new folder. 2. touch upload.conf New File

 

7. Configure nginx in upload.conf file

 

> 1. The input terminal cd upload, the destination folder member, enter vim upload.conf. Edits

Guess you like

Origin www.cnblogs.com/boye-1990/p/12119346.html