/ 25浏览

Nginx 适用于 Mac

安装nginx

$ brew install nginx

启动

$ nginx    //localhost:8080  可以看到表示正常启动
$ nginx -v  //版本

停止

$ nginx -s stop

重启

$ nginx -s reload

localhost:8080​ 的根目录位置

usr > 本地 > var > www 下

环境

设定档案在/usr/local/etc/nginx/nginx.conf​ 也可以在servers​目录里面加入.conf​档

server配置

shenhuanjie.nat200.top​路径透过proxy​导入到localhost:8877
shenhuanjie.nat200.topm/leo/cgi-bin​导入到localhost:8888/leo/cgi-bin

server {
    listen       80;
    server_name  shenhuanjie.nat200.top;
  
    location / {
      proxy_pass http://localhost:8877;
    }

    location /leo/cgi-bin {
    	proxy_pass http://localhost:8888/leo/cgi-bin;
    }
}

localhost:8877​ 指向绝对路径的资料夹开启index.html

server {
    listen       8877;
    server_name  localhost;

    location / {
        root /Users/shenhuanjie/Desktop/work/ifttt/dist/;
        index  index.html index.htm;
    }
}

如果要在本地使用网域取代localhost​ 可以在/etc/hosts​文件下配置成这样

原来的

127.0.0.1		localhost
255.255.255.255	broadcasthost
::1             localhost

修改后

127.0.0.1		localhost
255.255.255.255	broadcasthost
::1             localhost
127.0.0.1 		shenhuanjie.nat200.top

这样dns就会优先判断这个leonsnoopyleo.com​网域指向到本机

开启php

nginx.conf​ 这个注解拿掉

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