Nginx 编译安装
1 利用下面的命令来检查系统是否安装了apache
如果已安装,由于apache和nginx 默认端口都是 80 所以如果nginx 要以80端口启动 那么需要将apache卸载或者关闭或者更改apache的端口 命令:
- 卸载 apache:
- yum -y remove httpd
- 关闭 apache:
- service httpd stop
- 修改 apache 端口:
- vim /etc/httpd/conf/httpd
- Listen 80 修改成其他端口 如 8000 ....
2 更新系统 (根据要求配置而决定)
3 安装编译需要的组件(可根据自己的需求添加 以下为一般用户的需求)
4 选择或者创建目录 (下载编译包的位置)
5 下载 安装 pcre组件 (如果上面yum 安装的时候已安装 pcre pcre-devel 可不进行此操作)
- wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
- tar zxf pcre-8.35.tar.gz
- cd pcre-8.35
- ./configure
- make (如果提示 -bach make 安装make即可 命令 yum install make)
- make install
- make && make install
- cd /usr/local/src
- wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
- tar zxvf ngx_cache_purge-2.3.tar.gz
6 进入Nginx 的安装目录 下载安装
- cd /usr/local/src
- wget http://nginx.org/download/nginx-1.6.0.tar.gz
- tar -xzf nginx-1.6.0.tar.gz
- cd nginx-1.6.0
- 简易配置
- ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module
- 多功能配置
- ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --add-module=/usr/local/src/ngx_cache_purge-2.3 --with-pcre=/usr/local/pcre-8.35 --with-http_image_filter_module --with-http_dav_module --with-http_flv_module --with-http_random_index_module --with-http_secure_link_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-http_gunzip_module --with-http_auth_request_module
- --with-http_geoip_module 启用ngx_http_geoip_module支持(该模块创建基于与MaxMind GeoIP二进制文件相配的客户端IP地址的ngx_http_geoip_module变量) 添加此功能需先安装 GeoIP 可编译安装 可 yum 安装 yum install GeoIP GeoIP-devel
- make && make install
7 创建nginx的用户 不必须 需要指定用户跑nginx 服务才执行
useradd -g www www #加www用户到www组中
8 创建proxy配置文件
添加如下内容:
- proxy_redirect off;
- proxy_set_header Host $host;
- proxy_set_header Port $proxy_port;
- proxy_set_header XHost $host:$proxy_port;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header REMOTE_ADDR $remote_addr;
- proxy_set_header HTTP_CLIENT_IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- #proxy_headers_hash_max_size 512;
- #proxy_headers_hash_bucket_size 512;
- #client_max_body_size 10m;
- client_body_buffer_size 128k;
- proxy_connect_timeout 30;
- proxy_send_timeout 30;
- proxy_read_timeout 30;
- proxy_buffers 32 4k;
- proxy_buffer_size 16k;
- expires 60;
- client_body_timeout 60;
- client_header_timeout 60;
9 创建Nginx配置文件
先将原文件备份或删除:
简单配置内容如下:
- worker_processes 2;
- worker_rlimit_nofile 65535;
- error_log /var/log/nginx/error.log notice;
- pid /var/run/nginx.pid;
- events {
- worker_connections 51200;
- use epoll;
- }
- http {
- include proxy.conf;
- include mime.types;
- default_type application/octet-stream;
- log_format main '$host $remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for" '
- '"$upstream_addr" "$upstream_http_host"';
- # access_log /var/log/nginx/access.log main;
- sendfile on;
- tcp_nopush on;
- server_tokens off;
- tcp_nodelay on;
- keepalive_timeout 15;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 256k;
- gzip_http_version 1.0;
- gzip_vary on;
- gzip_disable "MSIE [1-6]\.";
- gzip_comp_level 7;
- gzip_types text/plain image/gif image/jpeg image/png application/javascript application/x-javascript application/xml application/json application/xml+rss text/css text/javascript;
- upstream backend {
- server 127.0.0.1:8000;
- }
- upstream backend_new {
- server 127.0.0.1:8080;
- }
- limit_conn_zone $binary_remote_addr zone=addr:10m;
- limit_req_zone $binary_remote_addr zone=req_one:10m rate=15r/s;
- proxy_temp_path /var/log/nginx/proxy_temp/temp;
- proxy_cache_path /var/log/nginx/proxy_temp/cache levels=1:2 keys_zone=cache:10m max_size=100m;
- proxy_cache_key "$scheme://$host$uri";
- include sites/*.conf;
- }
-
10 最后启动nginx (此时 Nginx 不是开机启动 Nginx 开机启动)
nginx 配置 http://blog.csdn.net/shuihan0377/article/details/5822736
###############################################################################################
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
从错误看出是缺少lib文件导致,进一步查看下
[root@localhost conf]# ldd $(which /usr/local/nginx/sbin/nginx)
linux-gate.so.1 => (0x0071b000)
libpthread.so.0 => /lib/libpthread.so.0 (0×00498000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0×00986000)
libpcre.so.1 => not found
libcrypto.so.6 => /lib/libcrypto.so.6 (0×00196000)
libz.so.1 => /lib/libz.so.1 (0×00610000)
libc.so.6 => /lib/libc.so.6 (0x002d7000)
/lib/ld-linux.so.2 (0x006a8000)
libdl.so.2 => /lib/libdl.so.2 (0x008c3000)
可以看出 libpcre.so.1 => not found 并没有找到,进入/lib目录中手动链接下
# cd /lib (注意 32位和64位 目录不同 lib64)
# ln -s libpcre.so.0.0.1 libpcre.so.1
然后在启动nginx ok 了
##########################################################################
没有评论