nginx是高性能的http和反向代理服務(wù)器,也是一個IMAP/POP3/SMTP服務(wù)器
安裝homebrew(mac套件管理器)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝nginx
brew install nginx
安裝后使用nginx -v查看nginx版本
配置nginx
- 進(jìn)入nginx的安裝目錄,打開nginx.conf文件
cd /usr/local/etc/nginx/
sudo vi nginx.conf
- 對nginx.conf文件進(jìn)行配置,詳解:
user tongtong staff;
#user root;
# 在配置文件的頂級main部分,代表worker角色的工作進(jìn)程個數(shù)
worker_processes 1;
# 錯誤日志
error_log /var/log/nginx/error_log;
error_log logs/error.log notice;
error_log logs/error.log info;
# 進(jìn)程文件
#pid logs/nginx.pid;
events {
# 寫在events部分,每一個worker進(jìn)程能并發(fā)處理(發(fā)起)的最大連接數(shù)
worker_connections 1024;
}
http {
# 文件擴(kuò)展名與文件類型映射表
include mime.types;
# 設(shè)定默認(rèn)文件類型
default_type application/octet-stream;
# 為nginx服務(wù)器設(shè)置詳細(xì)的日志格式
#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記錄了哪些用戶,哪些頁面以及用戶瀏覽器,ip和其他的訪問信息,access_log路徑
#access_log logs/access.log main;
# 開啟高效文件傳輸模式,sendfile指令指定nginx是否調(diào)用sendfile函數(shù)來輸出文件,對于普通應(yīng)用設(shè)為 on,如果用來進(jìn)行下載等應(yīng)用磁盤IO重負(fù)載應(yīng)用,可設(shè)置為off,以平衡磁盤與網(wǎng)絡(luò)I/O處理速度,降低系統(tǒng)的負(fù)載。注意:如果圖片顯示不正常把這個改成off。
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# 配置信息文件夾
include conf.d/*.conf;
# 虛擬主機(jī)配置
server {
# 監(jiān)聽端口
listen 8080;
# 域名設(shè)定,可以有多個
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
# 定義路徑下默認(rèn)訪問的文件名
index index.html index.htm;
# 打開目錄瀏覽功能,可以列出整個目錄
autoindex on;
}
#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服務(wù)器監(jiān)聽端口與地址,可以是本機(jī)或者其它
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# fastcgi配置
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#允許/禁止某個ip/ip段訪問文件
#location ~ /\.ht {
# deny all;
#}
}
}
- 測試配置是否成功
nginx默認(rèn)監(jiān)聽的端口是8080
- 啟動nginx:sudo nginx
- 重啟nginx:sudo nginx -s reload
- 查看nginx進(jìn)程:ps -ef | grep nginx
- 殺死進(jìn)程 kill [[pid]
? ~ ps -ef | grep nginx
501 2489 382[pid] 0 6:50下午 ttys002 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx
??補(bǔ)充 ps -ef | grep nginx:這條命令的意思是顯示有關(guān)Apachejetspeed的進(jìn)程
| 解釋 | |
|---|---|
| ps | 將某個進(jìn)程顯示出來 |
| -A | 顯示所有程序 |
| -e | 此參數(shù)的效果和指定"A"參數(shù)相同 |
| -f | 顯示UID,PPIP,C與STIME欄位。 |
| grep | 查找 |
| | | 管道命令,表示命令同時執(zhí)行 |