centos下安装nginx

mkdir /usr/local/nginx
cd /usr/local/nginx/

从http://nginx.org/download/上下载相应的版本,比如下载nginx-1.5.9.tar.gz

解压tar.gz文件 

tar -zxvf nginx-1.5.9.tar.gz

将解压后的文件内容放到/usr/local/nginx下,执行以下命令

./configure --prefix=/usr/local/nginx

如果出现

checking for C compiler ... not found

这个错误就执行

yum -y install gcc gcc-c++ autoconf automake make

如果出现

./configure: error: the HTTP rewrite module requires the PCRE library.

这个错误就执行

yum -y install openssl openssl-devel

安装完成后再次执行

./configure --prefix=/usr/local/nginx

在当前目录下编译和安装

make && make install

完成后启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

重启命令

/usr/local/nginx/sbin/nginx -s reload

还可以通过以下命令判断配置文件是否正确

nginx -t -c /usr/local/nginx/conf/nginx.conf
或者

/usr/local/nginx/sbin/nginx -t

nginx.conf配置文件内容

user  nginx;
#user root;
worker_processes  8;

events {
    worker_connections  204800;
user  nginx;
#user root;
worker_processes  8;

events {
    worker_connections  204800;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    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 text/javascript application/javascript application/xml;
    gzip_vary on;
    # client_max_body_size 8m;
    client_max_body_size 800m;

    log_format  main  '$remote_addr - $remote_user [$time_local]'
                      '"$request" $status $body_bytes_sent'
                      '"$http_referer" "$http_user_agent"'
                      '"$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    #include proxy.conf;

    #include ../conf.d/mg;
    include ../conf.d/xcxweb.8092;
    include ../conf.d/signature.8090;
    include ../conf.d/creditauth.8093;
    include ../conf.d/financial.8094;
    #include ../conf.d/es;
}

在/usr/local/nginx/conf.d目录下有附加的配置文件内容为

server {
        listen 9502;
        server_name webapi.xxx.com;
        ssl on;
        ssl_certificate   /usr/local/nginx/cert/xxx.com.pem;
        ssl_certificate_key  /usr/local/nginx/cert/xxx.com.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        charset utf-8;

        #       location ^~ /res/m/common/ {
        #   gridfs xxx root_collection=COMMON field=filename type=string user=xxx pass=xxx;
        #    mongo 127.0.0.1:27017;
        #}

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|mp3|htm|ico|html|tpl|json|txt|woff|woff2|eot|svg|ttf|otf|p12)$ {
            root /home/img;
                }

        location ~ /eureka {
             proxy_pass http://172.17.2.91:9001;
             proxy_set_header   Host             webapi.xxx.com;
             proxy_set_header   X-Real-IP        $remote_addr;
             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_read_timeout 3000s;
             proxy_http_version 1.1;
             proxy_set_header Connection "";

             add_header Cache-Control no-store;
        }

        location ~ /xcxweb {
             proxy_pass http://172.17.2.91:9091;
             proxy_set_header   Host             webapi.xxx.com;
             proxy_set_header   X-Real-IP        $remote_addr;
             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_read_timeout 3000s;
             proxy_http_version 1.1;
             proxy_set_header Connection "";

             add_header Cache-Control no-store;
        }
        access_log  logs/xxx.access.log main;
        location ~ /\.ht {deny  all;}
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值