安装nginx

Mac下安装nginx

准备

如果没有安装homebrew,需要先执行以下命令安装。

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装

在终端命令中输入:

brew install nginx

等待安装完成。

/usr/local/var/www #默认网站路径
/usr/local/etc/nginx/nginx.conf #默认配置文件,默认端口8080,修改此配置文件的listen改为80端口
/usr/local/etc/nginx/servers/ #默认加载配置文件夹
/usr/local/Cellar/nginx/1.8.1 #默认安装路径

开机启动
注意:~/Library/Library可能需要创建

ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

如果上面开机启动命令不对,可以 brew info nginx 查看信息

设置权限:

sudo chown root:wheel /usr/local/Cellar/nginx/1.8.1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.8.1/bin/nginx

重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit

测试配置是否有语法错误
nginx -t

更多详细 nginx 帮助信息:
nginx -h

我本地的一个配置信息(/usr/local/etc/nginx/nginx.conf)

    server {
        listen       80;
        server_name  test.com;
        root   html/test/public;

        location / {
                index  index.php;
                if (!-e $request_filename) {
                        rewrite  ^(.*)$  /index.php?s=$1  last;
                        break;
                }
        }

        location ~ \.php$ {
                send_timeout 60;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
    }

你可能感兴趣的:(安装nginx)