GCC,PCRE,zlib,OpenSSL等安装包
nginx-1.6.2.tar.gz openssl-1.0.1c.tar.gz pcre-8.35.tar.gz zlib-1.2.8.tar.gz
1)需要安装软件:GCC,PCRE,zlib,OpenSSL。 Nginx是C写的,需要用GCC编译;Nginx的Rewrite和HTTP模块会用到PCRE;Nginx中的Gzip用到zlib;
2)用命令“# gcc”,查看gcc是否安装;如果出现“gcc: no input files”信息,说明已经安装好了。命令:[root@localhost soft]# gccgcc: fatal error: no input files否则,执行命令:[root@localhost soft]# yum install gcc”,一直按y确认即可.
3)gcc测试:[root@localhost soft]# gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linuxThread model: posixgcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)
4)同样方法,用如下命令安装PCRE,zlib,OpenSSL;注:安装包下安装,即执行命令如下tar -zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8./configuremake make installtar -zxvf openssl-1.0.1c.tar.gzcd openssl-1.0.1c./configuremake make install
注:PCRE 作用是让 Ngnix 支持 Rewrite 功能。下载并解压 PCRE 安装包;[root@localhost soft]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz[root@localhost soft]# chmod 777 pcre-8.35.tar.gz [root@localhost soft]# tar -zxvf pcre-8.35.tar.gz
进入安装目录,编译并安装;[root@localhost soft]# pwd/home/sonar/soft[root@localhost soft]# cd pcre-8.35/[root@localhost pcre-8.35]# ./configure [root@localhost pcre-8.35]# make && make install
查看pcre版本;[root@localhost pcre-8.35]# pcre-config --version8.35说明:安装成功!
1)下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz;[root@localhost soft]# pwd/home/sonar/soft[root@localhost soft]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
2)解压安装包;[root@localhost soft]# chmod 777 nginx-1.6.2.tar.gz[root@localhost soft]# tar -zxvf nginx-1.6.2.tar.gz
3)进入安装目录,编译并安装;[root@localhost soft]# cd nginx-1.6.2[root@localhost nginx-1.6.2]# ./configure --prefix=/home/sonar/soft/nginx --with-pcre=/home/sonar/soft/pcre-8.35 --with-http_stub_status_module --with-debug[root@localhost nginx-1.6.2]# make [root@localhost nginx-1.6.2]# make install
4)查看版本;[root@localhost nginx-1.6.2]# nginx -v
1)创建 Nginx 运行使用的用户 nginx:[root@localhost conf]# /usr/sbin/groupadd nginx[root@localhost conf]# /usr/sbin/useradd -g nginx nginx
2)配置nginx.conf ,将/home/sonar/soft/nginx/conf/nginx.conf替换为以下内容:user root;worker_processes 2; #设置值和CPU核心数一致error_log /home/sonar/soft/nginx/logs/nginx_error.log crit; #日志位置和日志级别pid /home/sonar/soft/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 65535;events{ use epoll; worker_connections 65535;}http{ include mime.types; 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'; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; #下面是server虚拟主机的配置 server { listen 8080;#监听端口 server_name localhost;#域名 index index.html index.htm index.php; root /home/sonar/soft/nginx/html;#站点目录 location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; # access_log off; } location ~ .*\.(js|css)?$ { expires 15d; # access_log off; } access_log off; }}
3)检查配置文件ngnix.conf的正确性命令;[root@localhost sbin]# pwd/home/sonar/soft/nginx/sbin[root@localhost sbin]# ./nginx -tnginx: the configuration file /home/sonar/soft/nginx/conf/nginx.conf syntax is oknginx: configuration file /home/sonar/soft/nginx/conf/nginx.conf test is successful
4)nginx启动命令:[root@localhost sbin]# pwd/home/sonar/soft/nginx/sbin[root@localhost sbin]# ./nginx 见图;
5)访问:http://localhost; 如图;Nginx 其他命令:/home/sonar/soft/nginx/sbin/nginx -s reload # 重新载入配置文件/home/sonar/soft/nginx/sbin/nginx -s reopen # 重启 Nginx/home/sonar/soft/nginx/sbin/nginx -s stop # 停止 Nginx
1)远程执行wget命令后,下载的文件需要执行有+X权限;
2)注意查看防火墙,是否启用nginx配置的端口;
3)如果出现403 forbidden,则说是权限异常,在nginx.conf中,指定下user ,如上步骤中user root;