Linux上安装nginx

来源:互联网 发布:淘宝网平板电脑版下载 编辑:程序博客网 时间:2024/06/07 20:08

如果迩是在ubuntun下安装nginx、建议先卸载掉自带的版本、太旧了

sudo apt-get --purge remove nginx

首先去找个源码吧、目前官网的最新稳定版是1.2.6、所以输入个

wget http://nginx.org/download/nginx-1.2.6.tar.gz

获取到当前目录、然后再解压啪啪的tar -zxf xxxx.tar.gz

然后就安装吧、从源码安装三步曲如果没有意外的话是狠顺利的、

./configure
make
sudo make install

先执行./configure后别急着往下执行、看看配置不是有有错了、如果不看清楚的话、执行make肯定会出问题、如果迩在make的时候看到出现

make: *** No rule to make target `build', needed by `default'.  Stop.这种现象、迩回头看看./configure的出错信息是不是没装某个组件、比如没装

伪静态模块需要pcre库、这是相常见的问题、没装就装上吧、目前pcre最新版本为8.12、如果迩想下载的话最好选择tar.gz的、当然官网也提供了压缩率更高的




ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library

需要安装pcre包。
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

你可能还需要安装
sudo apt-get install openssl libssl-dev


启动nginx  

/usr/local/nginx/sbin/nginx

Nginx反向代理设置 从80端口转向其他端口

找到conf/nginx.conf文件,编辑:

复制代码
复制代码
worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  127.0.0.1:8080;        location / {            proxy_pass   http://127.0.0.1:8080;        }    }}
复制代码
复制代码

server下的结点:

listen:监听80端口

server_name:转发到哪个地址

proxy_pass:代理到哪个地址

 

nginx常用命令(要进入到nginx的目录):

开启:start nginx

重启:nginx -s reload

 server {        listen       80;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            proxy_pass http://localhost:8080;            proxy_redirect off;            proxy_set_header Host $host;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            proxy_set_header X-Real-IP $remote_addr;        }