nginx在mac上的安装笔记

声明:以下只是简单介绍nginx的安装,还没有深入讲解nginx的相关配置以及功能


1.安装nginx

brew install nginx

如果出现一下结果 就证明已经安装了

Warning: nginx 1.12.0_1 is already installed

安装路径

➜  ~ ls /usr/local/Cellar/nginx/1.12.0_1
CHANGES                   LICENSE                   bin                       html
INSTALL_RECEIPT.json      README                    homebrew.mxcl.nginx.plist share

2.nginx 的配置

ls /usr/local/etc/nginx
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

主要是nginx.conf

➜  ~ cat /usr/local/etc/nginx/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       9990; #监听的端口
        server_name  localhost;#服务名称,也就是域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /Users/xinzhiyun/workspace/src/html-demo/metronic.bootstrap; #静态文件根路径,默认的是 /usr/local/var/www
            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 servers/*;
}
ls /usr/local/var/www 
50x.html           index.html         metronic.bootstrap

2.启动nginx

➜  ~ brew services start nginx
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

访问 localhost:9990
nginx在mac上的安装笔记_第1张图片

3.停止nginx

➜  ~ brew services stop nginx
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)

4.重新启动nginx

➜  ~ brew services restart nginx 
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

你可能感兴趣的:(nginx,nginx)