学习第一步,安装第一步
说明: 本文章在 mac 系统 Intel core 下操作的 安装的 nginx version 是 1.23.3
brew🔗: brew.sh/
brew 常用命令:
- brew help # 查看 brew 的帮助
- brew help [COMMAND] # brew help services
- nginx -h # 查看 nginx 的帮助
nginx install
1. brew 安装 nginx
brew install nginx
2. 检查是否安装成功
nginx -v # 查看 nginx version,显示 nginx version: nginx/xx.xx.xx 即表示安装成功
3. brew 开启服务
查看服务是否开启成功 http://localhost:8080 , 看到 welcome 则说明成功
brew services start nginx # brew services start xxx 即开启 xxx 服务
查看安装目录和配置文件讲解
查看安装目录:
brew info nginx
// The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo,可以找到 nginx.conf 配置文件
- cd /usr/local/etc/nginx
- ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default servers win-utf
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params
fastcgi_params koi-win nginx.conf scgi_params.default uwsgi_params.default
查看配置文件:
- cat nginx.conf
#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;
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 servecies/* 说明可以在 servecies 下新建一个配置文件,
# 并且该文件可以将新建的配置文件包含进来,避免该文件过大
include servers/*;
}
术语解释
CGI 通用网关协议
- CGI (common gateway interface) 通用网关接口
- Web Server 通过 CGI 协议可以把动态的请求传递给对应的应用程序(如 php、jsp、python、node)
- FastCGI 实际上是增加了一些扩展功能的 CGI, 是 CGI 的改进,描述了客户端和 Web 服务器程序之间传输数据的一种标准
- SCGI 协议是 CGI 的替代品,它是一个应用于 HTTP 服务器的借口标准,它的设计更加容易实现