centos 6.6编译安装nginx

时间:2023-03-09 00:28:31
centos 6.6编译安装nginx

nginx 安装

安装前必要软件准备

1)安装pcre、gzip 等
为了支持rewrite功能,我们需要安装pcre

# yum install -y  pcre* zlib zlib-devel openssl-devel

centos 6.6编译安装nginx

2)下载

wget http://nginx.org/download/nginx-1.8.0.tar.gz

2)解压切到目录下

# tar zxvf nginx-1.8..tar.gz

3)编译安装

创建nginx安装目录:

mkdir /data/nginx

进入nginx编译文件目录,编译文件

# cd nginx-1.8.0 
# ./configure \ --prefix=/data/nginx \ 指向安装目录 --sbin-path=/usr/sbin/nginx \ 指向(执行)程序文件(nginx --conf-path=/etc/nginx/nginx.conf \ 指向配置文件(nginx.conf) --error-log-path=/var/log/nginx/error.log \ 指向错误日志目录 --http-log-path=/var/log/nginx/access.log \ 指向错误日志目录 --pid-path=/var/run/nginx/nginx.pid \ 指向pid文件(nginx.pid) --lock-path=/var/lock/nginx.lock \ 指向lock文件(nginx.lock)(安装文件锁定,防止安装文件被别人利用,或自己误操作。) --user=user \ 指定程序运行时的用户 --group=nobody \ 指定程序运行时的用户组 --with-http_ssl_module \ 支持openssl --with-http_flv_module \ 启用ngx_http_flv_module支持 --with-http_stub_status_module \ 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态) --with-http_gzip_static_module \ 在线实时压缩输出数据流 --http-client-body-temp-path=/var/tmp/nginx/client/ \ 设定http客户端请求临时文件路径 --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 设定http代理临时文件路径 --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 设定http fastcgi临时文件路径 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 设定http uwsgi临时文件路径 --http-scgi-temp-path=/var/tmp/nginx/scgi \ 设定http scgi临时文件路径

4)make 和 make install

# make && make install

centos 6.6编译安装nginx

5)启动nginx

# cd /data/nginx/sbin

# ./nginx

使用命令看nginx已经启动并监听了80端口

# netstat -ntulp | grep ""

centos 6.6编译安装nginx

使用命令来测试,可以看到nginx已经成功提供服务

# curl -s http://localhost | grep nginx

centos 6.6编译安装nginx

或者直接在浏览器访问网站的80端口:

centos 6.6编译安装nginx

nginx安装完成 ^_^

nginx配置

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
gzip on; server {
server_name www.abc.cn;
listen ssl; ssl_certificate /data/cert/1697401_www.abc.cn.pem;
ssl_certificate_key /data/cert/1697401_www.abc.cn.key;
proxy_redirect http:// $scheme://;
location / {
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_send_timeout ;
proxy_read_timeout ;
proxy_buffer_size 4k;
proxy_buffers 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
proxy_pass http://localhost:81;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}

  server{
    listen 80;
    server_name s.smk5s.cn;
    location / {
      root /data/mmall/mmall/;
      expires 7d;
      add_header Access-Control-Allow-Origin *;
      }
    }


    server{
      listen 80;
      server_name adminsmk.wefallin.cn;
      location / {
        root /data/mmall/mmall/backend/dist;
        index index.html;
      }
    }

}