日期:2014-05-16  浏览次数:20636 次

linux下 nginx 初探之反向代理及虚拟目录

本文是基本已经安装nginx的前提下,若是未安装 sudo aptitude install nginx 即可!


一 反向代理
配置文件默认是在 /etc/nginx/nginx.conf
最新nginx是通过include指令读取其他的配置文件

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

我们不需要改变这个自带的版本,有也不宜去改变。copy一份出来
cp /etc/nginx/nginx.conf ?/home/inter12/base/config/ ?#这个可以是你自己的任何目录

vim /home/inter12/base/config/nginx.conf 添加server

http {
....
  server {
  
     listen 9090;
     server_name localhost
  }
  ... 
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
....
}

?
先暂时不需要理会是什么意思,确认下配置文件是否正确。
nginx -t -c /home/inter12/base/config/nginx.conf
nginx: the configuration file /home/inter12/base/config/nginx.conf syntax is ok
nginx: configuration file /home/inter12/base/config/nginx.conf test is successful
则表明是OK的。每次修改配置文件后,都可以采用这个命令来进行检查!

那么启动服务
nginx -c /home/inter12/base/config/nginx.conf
查看服务是否启动
ps -ef | grep nginx
netstat -anpl | grep 9090