Nginx安装
linux安装
下载 tar.gz 包,以及依赖 openssl、zlib、pcre
openssl、zlib、pcre 安装
1cd 对应目录 2./configure 3make 4make install
nginx 安装
1cd 对应目录 2./configure --with-pcre=pcre路径 --with-zlib=zlib路径 --with-openssl=openssl路径 3make 4make 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 默认配置
默认配置如下
1user nginx; 2worker_processes 1; #启用的进程数,根据cpu数量配置 3 4error_log /var/log/nginx/error.log warn; #错误日志输出文件 5pid /var/run/nginx.pid; 6 7 8events { 9 worker_connections 1024; #单个后台worker process进程的最大并发链接数 10} 11 12 13http { 14 include /etc/nginx/mime.types; #设定mime类型,类型由mime.type文件定义 15 default_type application/octet-stream; 16 17 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 18 '$status $body_bytes_sent "$http_referer" ' 19 '"$http_user_agent" "$http_x_forwarded_for"'; #设定日志格式 20 21 access_log /var/log/nginx/access.log main; #日志输出文件 22 23 sendfile on; 24 #tcp_nopush on; 25 26 keepalive_timeout 65; #连接超时时间 27 28 #gzip on; #开启gzip压缩 29 30 include /etc/nginx/conf.d/*.conf; 31} 32 33 34server { 35 listen 80; #监听端口 36 server_name localhost; #使用localhost访问时 37 38 #charset koi8-r; 39 #access_log /var/log/nginx/log/host.access.log main; #设定本虚拟主机的访问日志 40 41 location / { 42 root /usr/share/nginx/html; #服务器网站根目录 43 index index.html index.htm; #首页文件的名称 44 } 45 46 #error_page 404 /404.html; 47 48 # redirect server error pages to the static page /50x.html 49 # 50 error_page 500 502 503 504 /50x.html; # 定义错误提示页面 51 location = /50x.html { 52 root /usr/share/nginx/html; 53 } 54 55 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 56 # php脚本请求转发到 http://127.0.0.1 57 #location ~ \.php$ { 58 # proxy_pass http://127.0.0.1; 59 #} 60 61 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 62 # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置. 63 #location ~ \.php$ { 64 # root html; 65 # fastcgi_pass 127.0.0.1:9000; 66 # fastcgi_index index.php; 67 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 68 # include fastcgi_params; 69 #} 70 71 # deny access to .htaccess files, if Apache's document root 72 # concurs with nginx's one 73 # 禁止访问 .htxxx 文件 74 #location ~ /\.ht { 75 # deny all; 76 #} 77}