nginx

服务的启动

http://www.cnblogs.com/wyd168/p/6636529.html

启动一个nginx服务:

进入到 /usr/local/nginx/sbin目录

sudo  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
View Code

 

得到所有正在运行的nginx进程

ps -ax | grep nginx

重启nginx

进入/usr/local/nginx/sbin
sudo ./nginx -s reload

 

配置文件结构

1、简单指令

2、块级指令:用 {和} 大括号包裹的额外指令集

 在配置文件中,没有放在任何上下文中的指令都是处在主上下文中。events 和 http 的指令是放在主上下文中,server 放在 http 中, location 放在 server 中。

静态服务器

listen监听的端口号,server_name 是服务名,

location: 根据正则表达进行匹配,进入到不同的location

 

在本地创建如下文件夹: /data/index,在index里创建一个简单html文件,hello.html
可以通过 http://localhost:8090/index/hello.html 访问到本地文件
server { listen
8090; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} location /index { root /data; #此时会访问本地/data/index文件夹 } }

 

搭建简单代理服务器:

我们将配置一个基本的代理服务器,将处理首页请求,并返回请求给其他的被代理的服务器。这两个server将放在一个nginx实例中,

 

 server {
        listen 8089;
        root /data/up1;
        location / {
            }
    }
    server {
        listen       8090;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

     
        location / {
            #root /data;
            proxy_pass http://localhost:8089;
        }

 

posted @ 2017-08-07 11:35  zhaop  阅读(143)  评论(0编辑  收藏  举报