mac下如何安装Nginx
首先要先安装homebrew
1 用brew命令查询Nginx
bash-3.2$ brew search nginx
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 4990, done.
remote: Counting objects: 100% (4990/4990), done.
remote: Compressing objects: 100% (4760/4760), done.
remote: Total 4990 (delta 53), reused 1200 (delta 39), pack-reused 0
Receiving objects: 100% (4990/4990), 4.00 MiB | 77.00 KiB/s, done.
Resolving deltas: 100% (53/53), done.
Checking out files: 100% (5007/5007), done.
Tapped 2 commands and 4775 formulae (5,032 files, 12.5MB).
==> Formulae
nginx homebrew/core/nginx homebrew/core/nginx
2 执行安装Nginx命令
bash-3.2$ brew install nginx
==> Installing dependencies for nginx: openssl and pcre
==> Installing nginx dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2r.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/c1/c1f8c06740398325c7028213b20b18c5de39763fbc81e5819c7
######################################################################## 100.0%
==> Pouring openssl-1.0.2r.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
==> Summary
🍺 /usr/local/Cellar/openssl/1.0.2r: 1,795 files, 12.1MB
==> Installing nginx dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.43.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/08/08e7414a7641d1e184c936537ff67f72f52649374d2308b896d
######################################################################## 100.0%
==> Pouring pcre-8.43.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/pcre/8.43: 204 files, 5.5MB
==> Installing nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.15.12.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/f2/f2084e7e6ec97658001039be1be07aaaaae760427c990b1075c
######################################################################## 100.0%
==> Pouring nginx-1.15.12.mojave.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Summary
🍺 /usr/local/Cellar/nginx/1.15.12: 25 files, 2MB
==> `brew cleanup` has not been run in 30 days, running now...
Pruned 13 symbolic links and 5 directories from /usr/local
==> Caveats
==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
==> nginx
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
进入Nginx文件目录中
- 默认的目录为/usr/local/etc/nginx
查询Nginx配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#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 {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
"nginx.conf" 117L, 2680C
启动Nginx
nginx
运行效果
页面输入http://127.0.0.1:8080/
image.png
网友评论