Nginx安装
linux安装
下载 tar.gz 包,以及依赖 openssl、zlib、pcre
openssl、zlib、pcre 安装
cd 对应目录
./configure
make
make install
nginx 安装
cd 对应目录
./configure --with-pcre=pcre路径 --with-zlib=zlib路径 --with-openssl=openssl路径
make
make install
ps:./configure 用法 参考
http://www.linuxidc.com/Linux/2011-02/32211.htm
http://www.cnblogs.com/tdalcn/archive/2011/11/11/2245402.html
./configure -prefix=/usr 意思是将该软件安装在 /usr 下面,执行文件就会安装在 /usr/bin,资源文件就会安装在 /usr/share(而不是默认的/usr/local/share),具体可以通过 --help 查看。
windows安装
官网下载windows版本 安装之后,双击启动(窗口会一闪而过,会有两个nginx进程,应该是主和从)
Nginx 默认配置
默认配置如下
user nginx;
worker_processes 1; #启用的进程数,根据cpu数量配置
error_log /var/log/nginx/error.log warn; #错误日志输出文件
pid /var/run/nginx.pid;
events {
worker_connections 1024; #单个后台worker process进程的最大并发链接数
}
http {
include /etc/nginx/mime.types; #设定mime类型,类型由mime.type文件定义
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; #设定日志格式
access_log /var/log/nginx/access.log main; #日志输出文件
sendfile on;
#tcp_nopush on;
keepalive_timeout 65; #连接超时时间
#gzip on; #开启gzip压缩
include /etc/nginx/conf.d/*.conf;
}
server {
listen 80; #监听端口
server_name localhost; #使用localhost访问时
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; #设定本虚拟主机的访问日志
location / {
root /usr/share/nginx/html; #服务器网站根目录
index index.html index.htm; #首页文件的名称
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; # 定义错误提示页面
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
# php脚本请求转发到 http://127.0.0.1
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
# 禁止访问 .htxxx 文件
#location ~ /\.ht {
# deny all;
#}
}