Mac下配置虚拟主机

来源:互联网 发布:js获取传入的参数 编辑:程序博客网 时间:2024/06/08 13:56

Mac下配置虚拟主机

mac下配置虚拟主机
查看Nginx配置文件路径,在不同的安装环境配置下配置文件的路径不相同
➜  nginx brew info nginxnginx: stable 1.12.1 (bottled), devel 1.13.4, HEADHTTP(S) server and reverse proxy, and IMAP/POP3 proxy serverhttps://nginx.org//usr/local/Cellar/nginx/1.12.1 (23 files, 1MB) *  Poured from bottle on 2017-08-29 at 10:52:21From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb==> DependenciesRequired: pcre ✔, openssl@1.1 ✔Optional: passenger ✘==> Options--with-debugCompile with support for debug log--with-gunzipCompile with support for gunzip module--with-passengerCompile with support for Phusion Passenger module--with-webdavCompile with support for WebDAV module--develInstall development version 1.13.4--HEADInstall HEAD version==> CaveatsDocroot is: /usr/local/var/wwwThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that  //Nginx配置文件路径nginx can run without sudo.   nginx will load all files in /usr/local/etc/nginx/servers/.    To have launchd start nginx now and restart at login:  brew services start nginxOr, if you don't want/need a background service you can just run:  nginx
在上面的命令执行之后我们可以找到Nginx的配置文件路径地址:
/usr/local/etc/nginx/nginx.conf
使用vim 编辑器打开
➜  nginx sudo vim nginx.conf
server { 36         listen       80; //监听的端口 37         server_name  cangck.com; //域名访问 38 39         #charset koi8-r; 40 41         #access_log  logs/host.access.log  main; 42 43         location / { 44             root  /usr/local/var/www/Thinkphp/public; //网站的工程目录,也就是index.php的目录路径名称 45             index  index.php index.html index.htm;  //添加index.php 主要是让服务器能够去找到index.php文件 46         } 47 48         #error_page  404              /404.html; 49 50         # redirect server error pages to the static page /50x.html 51         # 52         error_page   500 502 503 504  /50x.html; 53         location = /50x.html { 54             root   html; 55         } 56 57         # proxy the PHP scripts to Apache listening on 127.0.0.1:80 58         # 59         #location ~ \.php$ { 60         #    proxy_pass   http://127.0.0.1; 61         #} 62 63         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 64         # 65         location ~ \.php$ {//对php的设置参数 66             root           html; 67             fastcgi_pass   127.0.0.1:9000; 68             fastcgi_index  index.php; 69             fastcgi_param  SCRIPT_FILENAME /usr/local/var/www/Thinkphp/public$fastcgi_script_name;//配置脚本文件的路径,下面一行是
原始的配置信息,这需要把/scripts修改为index.php所在路径的全路径即可(/usr/local/var/www/Thinkphp/public) 70 #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 71             include        fastcgi_params; 72         }
添加域名相关的内容到/etc/hosts中即可:
➜  ~ cat /etc/hosts### Host Database## localhost is used to configure the loopback interface# when the system is booting.  Do not change this entry.##127.0.0.1localhost255.255.255.255broadcasthost::1             localhost127.0.0.1 cangck.com127.0.0.1 center.com127.0.0.1 onethink.com127.0.0.1 services.com127.0.0.1 localswagger.com127.0.0.1 swagger-editor.com127.0.0.1 wxpay.com➜  ~