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 {
#開啟目錄瀏覽功能
autoindex on; #開啟nginx目錄瀏覽功能
autoindex_exact_size off;#文件大小從kb開始顯示
autoindex_localtime on;#顯示文件修改時間為服務(wù)器本地時間
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 9000;#端口號設(shè)置為9000,默認(rèn)為8080根tomcat沖突
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime 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_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/*;
}
在/usr/local/etc/nginx/nginx.conf文件中。每次修改nginx.conf配置以后都要執(zhí)行以下命令檢查配置文件是否正確:
$ sudo /usr/local/Cellar/nginx/1.10.1/bin/nginx -t
如果顯示以下兩行信息,說明文件配置正確:
the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
configuration file /usr/local/etc/nginx/nginx.conf test is successful
然后輸入命令:$ps -ef |grep nginx獲取nginx的主進程號例如:20025
然后執(zhí)行以下命令即可使修改過的nginx配置文件生效:
$ sudo kill -HUP 20025
給予管理員權(quán)限
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx
給予管理員權(quán)限
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx
加入launchctl啟動控制
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
運行nginx(進入nginx/bin目錄)
$ sudo nginx #打開 nginx
$ nginx -s reload|reopen|stop|quit #重新加載配置|重啟|停止|退出 nginx
$ nginx -t #測試配置是否有語法錯誤
用法詳解
nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
選項列表
-?,-h : 打開幫助信息
-v : 顯示版本信息并退出
-V : 顯示版本和配置選項信息,然后退出
-t : 檢測配置文件是否有語法錯誤,然后退出
-q : 在檢測配置文件期間屏蔽非錯誤信息
-s signal : 給一個 nginx 主進程發(fā)送信號:stop(停止), quit(退出), reopen(重啟), reload(重新加載配置文件)
-p prefix : 設(shè)置前綴路徑(默認(rèn)是:/usr/local/Cellar/nginx/1.2.6/)
-c filename : 設(shè)置配置文件(默認(rèn)是:/usr/local/etc/nginx/nginx.conf)
-g directives : 設(shè)置配置文件外的全局指令
在瀏覽器中輸入IP:端口號,如果出現(xiàn)“welcome to nginx”則表示啟動成功!!
詳細(xì)解釋一下:目錄瀏覽功能
在nginx.conf文件里面的http{}內(nèi) 有個root,是設(shè)定網(wǎng)站的資源存放路徑
在nginx目錄下有個html的目錄,就是這個root目錄。在瀏覽器可以訪問該目錄下的文件,www文件可以自己mkdir,當(dāng)然名字可以隨意。
只要存放在html目錄下就都可以訪問。
說明:在/usr/local/var目錄下同樣存在一個www的目錄,這個目錄即為上面提到的html目錄,只是名字不同而已。
Tomcat
- 搜索tomcat是否存在:
brew search tomcat - 安裝tomcat:
brew install tomcat - 檢查是否安裝成功:
catalina -h - 運行tomcat:
catalina run
Tomcat的默認(rèn)端口是8080,如果運行成功可通過http://localhost:8080訪問
webapp的根目錄(CATALINA_HOME)為:/usr/local/Cellar/tomcat/7.0.33/libexec/webapps/ROOT/
MySQL
安裝MySQL
brew install mysql
cd /usr/local/opt/mysql/
修改配置文件
sudo vim my.cnf
#如果出現(xiàn)無法啟動mysql,rm my.cnf
加入launchctl啟動控制
mkdir -p ~/Library/LaunchAgents/
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#取消啟動
#launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
初始化 mysql
./bin/mysql_install_db
執(zhí)行安全設(shè)置腳本,設(shè)置root賬號密碼
./bin/mysql_secure_installation
命令行連接mysql
mysql -uroot -p
Mongo
brew install mongodb
第一次啟動服務(wù)端,這里需要做一些準(zhǔn)備工作.
- 默認(rèn)mongodb 數(shù)據(jù)文件是放到根目錄 data/db 文件夾下,如果沒有這個文件,請自行創(chuàng)建.
mkdir -p /data/db
注:給該文件夾賦權(quán)限,否則還是不能啟動服務(wù)
sudo chown id -u /data/db
- 如果你當(dāng)前的環(huán)境變量還沒有加入 mongod ,手動添加的環(huán)境變量中.
nano ~/.bash_profile
//添加mongodb安裝目錄到環(huán)境變量中
export PATH=/usr/local/Cellar/mongodb/2.4.9/bin:${PATH}
- 執(zhí)行此shell 讓環(huán)境變量馬上生效
source ~/.bash_profile - 修改mongodb配置文件,配置文件默認(rèn)在 /usr/local/etc 下的 mongod.conf
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /data/db
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 127.0.0.1
第二行修改成數(shù)據(jù)庫文件寫入目錄地址,如果準(zhǔn)備連接非本地環(huán)境的mongodb數(shù)據(jù)庫時,bind_ip = 0.0.0.0 即可.
- 使用mongod命令啟動服務(wù)
- 使用mongo命令行客戶端
/usr/local/etc$ mongo
Maven
brew install maven
mvn -v
Gradle
brew install gradle
brew info gradle