Nginx 学习笔记
2015-12-07 03:02
741 查看
nginx 以小巧,并发能力强而著称,其运行速度非常快。
下面以示例介绍我的学习过程。
第一次尝试使用Nginx,对其原理和使用方式都是摸索式的进行,所以所有测试都在本机完成。
下面以示例介绍我的学习过程。
第一次尝试使用Nginx,对其原理和使用方式都是摸索式的进行,所以所有测试都在本机完成。
一、源码编译安装
[code]wget http://nginx.org/download/nginx-1.7.1.tar.gz[/code]
为了不至于与sudo apt-get nginx的安装目录搞混淆,在这里我指定安装目录为/home/david/opt/nginx[code]./configure --prefix=/home/david/opt/nginx make && make install二、测试
为方便调试,切换目录到/home/david/opt/nginx[code] 启动 nginx: ./nginx 停止 nginx: ./nginx -s stop 关闭 nginx: ./nginx -s quit 重新加载配置:./nginx -s reload http://localhost 显示nginx的欢迎页三、 常用配置
3.1 当没有索引页时,显示文件和目录列表
编辑配置文件/home/david/opt/nginx/conf/nginx.conf[code] worker_processes 1; #服务进程数量,一般等于CPU数量 events { useepoll; #linux上使用epoll网络模型,可不配 worker_connections 1024; #一个worker_processe允许的最近并发连接数量 } location / { root html; index index.html index.htm; autoindex on; # 显示文件列表 autoindex_exact_size on; autoindex_localtime on; }3.2 虚拟文件目录
nginx 好像没有虚拟目录这个概念,但是可以通过指定请求路径时的访问路径实现,具体通过 alias 和 root 这两个参数设置,这两个参数非常容易混淆,导致出现404错误
现在要访问:/home/david/web/下form_get.html这个文件,如下配置:[code] # alias 实现 location ^~/web/ { alias /home/scada/david/web/; index index.html; autoindex on; # 显示文件列表 autoindex_exact_size on; autoindex_localtime on; } # root 实现 location ^~/web/ { root /home/david; index index.html; autoindex on; # 显示文件列表 autoindex_exact_size on; autoindex_localtime on; }
浏览器访问:http://127.0.0.1/web/
由于该目录没有索引文件,所有浏览器会显示目录树:
通过访问:http://127.0.0.1/web/form_get.html
效果如下:参考
http://tcspecial.iteye.com/blog/2077510
CGI热门博客
相关文章推荐
- Ubuntu安装Nginx 1.8.0
- Ubuntu15.10下安装Nginx,PHP5(及PHP-FPM),MySQL
- Nginx+nagios安装配置
- nginx实现负载均衡
- Linux下安装php,并配置到nginx【最终版,完美解决问题】
- 阿里云上搭建nginx+uwsgi+flask
- Nginx 配置SSL访问
- windows平台中配置nginx+php环境
- Nginx+uWSGI+Django部署
- nginx 1.9.7安装使用
- windows下安装以及配置nginx
- Mac 下使用 Homebrew 安装 Nginx
- nginx的缓存设置 expires缓存提升网站负载
- nginx gzip压缩提升网站速度
- nginx+php的编译
- Centos 7.0 安装nginx
- windows平台中配置nginx+php环境
- nginx rewrite 语法详解
- Django 部署(Nginx)
- CentOS 7 编译安装 Nginx 1.9.7