Mac下配置虚拟主机
mac下配置虚拟主机
查看Nginx配置文件路径,在不同的安装环境配置下配置文件的路径不相同
➜ nginx brew info nginx
nginx: stable 1.12.1 (bottled), devel 1.13.4, HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.12.1 (23 files, 1MB) *
Poured from bottle on 2017-08-29 at 10:52:21
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb
==> Dependencies
Required: pcre ✔, openssl@1.1 ✔
Optional: passenger ✘
==> Options
--with-debug
Compile with support for debug log
--with-gunzip
Compile with support for gunzip module
--with-passenger
Compile with support for Phusion Passenger module
--with-webdav
Compile with support for WebDAV module
--devel
Install development version 1.13.4
--HEAD
Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www
The 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 nginx
Or, 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.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 cangck.com
127.0.0.1 center.com
127.0.0.1 onethink.com
127.0.0.1 services.com
127.0.0.1 localswagger.com
127.0.0.1 swagger-editor.com
127.0.0.1 wxpay.com
➜ ~