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;#显示文件修改时间为服务器本地时间
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;#端口号设置为9000,默认为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配置以后都要执行以下命令检查配置文件是否正确:
$ 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
然后执行以下命令即可使修改过的nginx配置文件生效:
$ sudo kill -HUP 20025
给予管理员权限
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx
给予管理员权限
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 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
-p prefix : 设置前缀路径(默认是:/usr/local/Cellar/nginx/1.2.6/)
-c filename : 设置配置文件(默认是:/usr/local/etc/nginx/nginx.conf)
-g directives : 设置配置文件外的全局指令
在浏览器中输入IP:端口号,如果出现“welcome to nginx”则表示启动成功!!
详细解释一下:目录浏览功能
在nginx.conf文件里面的http{}内 有个root,是设定网站的资源存放路径
在nginx目录下有个html的目录,就是这个root目录。在浏览器可以访问该目录下的文件,www文件可以自己mkdir,当然名字可以随意。
只要存放在html目录下就都可以访问。
说明:在/usr/local/var目录下同样存在一个www的目录,这个目录即为上面提到的html目录,只是名字不同而已。
Tomcat
- 搜索tomcat是否存在:
brew search tomcat
- 安装tomcat:
brew install tomcat
- 检查是否安装成功:
catalina -h
- 运行tomcat:
catalina run
Tomcat的默认端口是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
#如果出现无法启动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
执行安全设置脚本,设置root账号密码
./bin/mysql_secure_installation
命令行连接mysql
mysql -uroot -p
Mongo
brew install mongodb
第一次启动服务端,这里需要做一些准备工作.
- 默认mongodb 数据文件是放到根目录 data/db 文件夹下,如果没有这个文件,请自行创建.
mkdir -p /data/db
注:给该文件夹赋权限,否则还是不能启动服务
sudo chown id -u /data/db
- 如果你当前的环境变量还没有加入 mongod ,手动添加的环境变量中.
nano ~/.bash_profile
//添加mongodb安装目录到环境变量中
export PATH=/usr/local/Cellar/mongodb/2.4.9/bin:${PATH}
- 执行此shell 让环境变量马上生效
source ~/.bash_profile
- 修改mongodb配置文件,配置文件默认在 /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
第二行修改成数据库文件写入目录地址,如果准备连接非本地环境的mongodb数据库时,bind_ip = 0.0.0.0 即可.
- 使用mongod命令启动服务
- 使用mongo命令行客户端
/usr/local/etc$ mongo
Maven
brew install maven
mvn -v
Gradle
brew install gradle
brew info gradle