ngin Finding Everything About Nginx Here

nginx如何安装

发表于 2015-06-19 阅读数 2227

1、安装nginx

> wget http://nginx.org/download/nginx-1.8.0.tar.gz

> tar zxvf nginx-1.8.0.tar.gz

> cd nginx-1.8.0

> ./configure && make && make install

(nginx默认安装目录为 /usr/local/nginx)


2、配置

编辑配置文件:/usr/local/nginx/conf/nginx.conf

worker_processes  1;

daemon  on;


events {

    worker_connections  1240;

}


http {

    include       mime.types;

    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '{$request_body} $status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  logs/access.log  main;


server {

listen       80;

server_name  localhost;


#默认路径

location / { 

root   html;

index  index.html index.htm;

}


#与php通讯

location ~ \.php$ {

root           html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

}

}


3、运行

> /usr/local/nginx/sbin/nginx (正常启动)

> /usr/local/nginx/sbin/nginx -s reload (热启动)

> /usr/local/nginx/sbin/nginx -s stop (正常停止)

(热启动是指修改完配置文件,不想停止nginx运行,无缝重新让nginx配置生效)