Nginx 安装
系统平台:CentOS release 6.6 (Final) 64位。
一、安装编译工具及库文件
yum -y install make zlib zlibdevel gccc++ libtool openssl openssldevel
二、首先要安装 PCRE
PCRE 作用是让 Ngnix 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址:http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@bogonsrc]# wgethttp://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包:
tar zxvf pcre-8.35.targz
3、进入安装包目录
cd pcre8.35
4、编译安装
root@bogonpcre ./configure make&& make install
5、查看pcre版本
pcreconfig --version
安装 Nginx
1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz
//Nginx.org/download/Nginx-1.6.2.tar.gz
2、解压安装包
tar zxvf Nginx1.6.2.tar 3、进入安装包目录cd Nginx2
root@bogonNginx2configure prefix=/usr/local/webserverNginx --withhttp_stub_status_module http_ssl_module pcresrc8.35 #--prefix=/usr/local/webserver/Nginx Nginx 配置文件 --with-prce=/usr/local/src/prce-8.35 prce安装目录 make 5、查看Nginx版本
usr/Nginxsbinv到此,Nginx安装完成。
Nginx 配置
root@bogonconfgroupadd www useradd g www www
配置Nginx.conf ,将/usr/local/webserver/Nginx/conf/Nginx.conf替换为以下内容
cat confconf user www www; worker_processes #设置值和cpu核心数一致 error_log logsNginx_errorlog crit#日志位置和日志级别 pid pid #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535 events { use epoll worker_connections } http include mimetypes default_type applicationoctetstream log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for' #charset gb2312; server_names_hash_bucket_size 128 client_header_buffer_size 32k large_client_header_buffers 4 client_max_body_size 8m sendfile on tcp_nopush on keepalive_timeout 60 tcp_nodelay on fastcgi_connect_timeout 300 fastcgi_send_timeout fastcgi_read_timeout fastcgi_buffer_size 64k fastcgi_buffers fastcgi_busy_buffers_size 128k fastcgi_temp_file_write_size gzip on gzip_min_length 1k gzip_buffers 16k gzip_http_version 1.0 gzip_comp_level gzip_types textplain applicationxjavascript textcss applicationxml gzip_vary on #limit_zone crawler $binary_remote_addr 10m;#下面是server虚拟主机的配置 server listen 80;#监听端口 server_name localhost;#域名 index indexhtml indexhtm indexPHP root html;#站点目录 location ~.*\.(|PHP5)?$ #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.00.1:9000 fastcgi_index index include fastcgi location gifjpgjpegpngbmpswfico) expires 30d # access_log off;jscss15d access_log off }
检查配置文件ngnix.conf的正确性命令:
t
启动 Nginx
Nginx 启动命令如下:
Nginx访问站点
从浏览器访问我们配置的站点ip:
Nginx 其他命令以下包含了 Nginx 常用的几个命令:
s reload # 重新载入配置文件s reopen # 重启 Nginxs stop # 停止 Nginx