Windows下Nginx的安装与配置(转)

1、首先去官网下载 nginx1.0.11的Windows版本,官网下载:http://nginx.org/download/nginx-1.0.11.zipphp

下载到软件包后,解压 nginx-nginx1.0.11.zip 包到你喜欢的根目录,并将目录名改成nginx。css

而后,执行下列操做:html

cd nginxnginx

start nginxapache

这样,nginx 服务就启动了。打开任务管理器,查看 nginx.exe 进程,有二个进程会显示,占用系统资源,那是至关的少。而后再打开浏览器,输入 http://127.0.0.1/  就能够看到nginx的欢迎页面了,很是友好浏览器

 nginx -s stop          // 中止nginx
nginx -s reload       // 从新加载配置文件
nginx -s quit          // 退出nginx服务器

 

今天搞了N久的虚拟目录配置,在几乎要放弃的时侯偶然看到一篇文章,将个人问题搞定ui

 

个人需求是这样的,系统有一个专门的文件夹用于存放图片,css,js或者附件,如:server

http://www.test.com/resources/images/a.jpghtm

http://www.test.com/resources/css/a.css

http://www.test.com/resources/js/a.js

http://www.test.com/resources/attach/a.doc

这样的配置对于apache来讲那至关容易,

须要经过location uri规则匹配访问到该文件夹,我使用以下配置:

location ^~ /resources/ {
    root d:/www/;
}

试了N屡次都能访问不到,一直报404,无比杯具!最后拜读了上面提供的blog才解决,发现跟原博主同样,没有真正搞清楚,location中root和alias的区别,最后修改为:

location ^~ /resources/ {
    alias d:/www/;
}

成功实现了个人需求。

原贴以下:

 

niginx 彷佛没有虚拟目录的说法,可是能够指定请求路径时nginx访问的路径,也算是一个解决办法。

(原文连接 http://ddbiz.com/?p=187)

server {
listen       80 default;
server_name  _;

location / {
root   html;
index  403.html;
}

location ~ //.ht {
deny  all;
}

    location /phpadmin/ {
alias   /opt/www/phpadmin/;
index   index.php;
}

location ~ /.php$ {
include httpd.conf;
}
}

要注意的是, location /phpadmin/ {} 和 location /phpadmin {} 是彻底不一样的。

前者能够访问到目录,然后者将被重定向到服务器,如: http://127.0.0.1/phpadmin ,将被重定向到 http://_/phpadmin

下面这个配置和上面基本相似,惟一的不一样是,全部对 /phpadmin/的访问将正确解析,而其余访问则返回页面不存在(404)的信息。

server {
listen       80 default;
server_name  _;

location / {
root   html;
#index  403.html;

return 404;
}

location ~ //.ht {
deny  all;
}

    location /phpadmin/ {
alias   /opt/www/phpadmin/;
index   index.php;
}

location ~ /.php$ {
include httpd.conf;
}
}

 

原贴地址:http://blog.sina.com.cn/s/blog_6c2e6f1f0100l92h.html

相关文章
相关标签/搜索