nginx之旅:安装及简单部署

安装之前最好了解一下nginx,参考nginx百度百科吧,下面这一句话基本概括了nginx的基本功能

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 

安装

安装很简单,直接去nginx官网下载源码即可,注意,是http://nginx.org/不是.com结尾的那个,.org一般是社区类网站,是免费的那种啦

linux安装一般没什么问题吧,我猜的下面说一下windows安装我遇到的问题吧:

1:不要直接点击exe文件,因为直接点击的话无论是否出现异常,都是一闪而过的,没什么意义

建议cmd进入命令行,进入nginx源码文件夹,虽然也是一样,但是方便后面敲命令,哈哈哈

>start nginx.exe

 

然后打开一个空选项卡,地址栏输入http://127.0.0.1/,如果出现传说中的欢迎页面,那祝贺你,你已经安装成功了

但是,我就没那么幸运了,我出现的是IIS的页面,摆明说明80端口被IIS占用了嘛

2:端口被占用,编译一下conf文件,发现是端口被占用的错误

D:\nginx>nginx -c D:\nginx\conf\nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: An attempt was made to access
a socket in a way forbidden by its access permissions)

 

网上搜索的做法吧把占用端口kill掉,其实我觉得没那么麻烦,既然80端口被占用,用其他的端口不就行了嘛

用文本编辑器打开nginx.conf文件,找到http context中的server中的listen指令,修改为自己喜欢的端口就好了

 

http {
    server {
        listen       8081;
        root D:/nginx/;
        location / {
            root data/www;
            index  index.html index.htm;
        }
        location /images/ {
            root data;
        }
    }
}

 

然后再编译一下,然后访问http://127.0.0.1:修改的端口号/ 就ok啦

简单部署

真的,挺建议看官方的教程的,看英文的最好http://nginx.org/en/docs/

下面英文的新手教程跟大家一起学习一下吧http://nginx.org/en/docs/beginners_guide.html

简单命令

nginx -s signal

Where signal may be one of the following:

  • stop — fast shutdown
  • quit — graceful shutdown
  • reload — reloading the configuration file
  • reopen — reopening the log files

强烈建议不要quit,直接reload是比较好的啦

简单的配置

首先,创建data/www目录,把一个 index.html的文件放进去;,并创建data/images目录,并把一些图片在里面。

http {
    server {
        listen       8081;
        root D:/nginx/;
        location / {
            root data/www;
            index  index.html index.htm;
        }
        location /images/ {
            root data;
        }
    }
}

 

代理配置

http {
    server {
        listen       8081;
        root D:/nginx/;
        location / {
               proxy_pass http://localhost:8089;
        }
        location ~/.(gif|jpg|png)$ {
            root /data/images;
        }
    }
    server {
        listen 8089;
        root D:/nginx/data/up1;
        location / {

        }
    }
}

 

详细的大家看英文教程,绝对简单容易上手无难度

最后上传一些截图和大家share一下

                                                         

                                                 

posted @ 2014-07-31 15:35  2BiTT  阅读(290)  评论(0编辑  收藏  举报