Mac上安装nginx
来源:互联网 发布:老虎机算法作弊器 编辑:程序博客网 时间:2024/04/30 06:07
1.brew install nginx
安装完成后,输出:
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that 监听8080端口
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
==> Summary
� /usr/local/Cellar/nginx/1.10.1: 7 files, 972.2K这里的目录指的是默认的web目录。
2.访问localhost:8080/:输出:
nginx欢迎界面。查看nginx.conf配置文件:
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
} 根目录是在html文件夹下。访问/usr/local/Cellar/nginx/1.10.1: 可以看到该目录下有:
xxxxxxxx
lrwxr-xr-x 1 xxx admin 16 4 23 14:24 html -> ../../../var/www
xxxxxxxxx
html目录下包含index.html.我们在html下新建一个文件夹,例如test,将/usr/local/Cellar/nginx/1.10.1/html/index.html移至/usr/local/Cellar/nginx/1.10.1/html/test/index.html。再次访问localhost:8080.提示forbidden。403.看来nginx不会自动去子文件夹下去寻找index.html.访问localhost:8080/test.正常加载了nginx欢迎页。所以,可以在设置的root目录下,设置多个子文件夹,每个文件夹内有自己的html文件。访问时,路径上要带上子文件夹的名字。否则,会403.
2.root 和alias
使用nginx设置root时要注意一个问题,就是如果该root设置的前端目录不是根目录,那么在写root的绝对地址时,要把前端目录的部分省略掉。
我们用设置虚拟目录指向的alias来和root比较一下就非常明显了
alias
location
/abc/
{
alias
/home/html/abc/
;
}
在这段配置下,http://test/abc/a.html就指定的是 /home/html/abc/a.html。这段配置亦可改成
root
location /abc/ {
root /home/html/;
}
可以看到,使用root设置目录的绝对路径时,少了/abc,也就是说,使用root来设置前端非根目录时,nginx会组合root和location的路径。
另外,使用alias时目录名后面一定要加“/”
- Mac上安装Nginx
- Mac上安装nginx
- Mac上安装nginx
- Mac上安装nginx
- 在mac上安装nginx
- 在mac上安装nginx
- Nginx Mac OX上安装
- 在mac上安装nginx
- 在Mac上安装nginx
- Nginx在Mac上的安装配置
- mac os上编译安装nginx php
- Mac上编译安装nginx报错
- Mac osx 10.10.5上安装NGINX
- mac上安装Nginx详细教程
- nginx在mac上的安装笔记
- mac 上安装nginx并且配置conf文件
- 在mac os x 10.9.2上安装nginx
- 如何在Mac上安装nginx以及所需模块
- C# 文件上传帮助类
- leetcode.70.Climbing Stairs
- Mysql中产生指定范围随机整型数
- KNN算法介绍(最邻近规则分类算法)
- ActivitiAPI
- Mac上安装nginx
- 【遇到的异常】initializationError(Runner:JUnit 4)
- 转 原来Github上的README.md文件这么有意思——Markdown语言详解
- 剑指offer 和为s的连续正数序列
- Java中的main()方法详解
- Subsequence POJ
- Install VPN PPTP Server on CentOS 6
- 打印一个数的二进制形式
- C# 处理数据类型转换帮助类