nginx安装及简单优化

一、安装

1.编译安装nginx

检查依赖:

rpm -qa pcre pcre-devel

rpm -qa openssl-devel openssl

下载:wgethttp://nginx.org/download/nginx-1.9.9.tar.gz

新建用户:useradd nginx -s /sbin/nologin -M

编译安装:

./configure --user=nginx --group=nginx --prefix=/home/nginx/nginx-1.9.9/ --with-http_stub_status_module --with-http_ssl_module

make && make install

2.启动:

/sbin/nginx 

二、优化

1.使用incloud方法简化规范配置文件

2.隐藏nginx版本号:


3.优化nginx进程数:

4 一般是服务器cpu内核数


4.优化绑定不同进程到不同cpu上面:

 0001 0010 0100 1000 分别代表0 1 2 3这四个cpu


nginx -t 验证配置文件是否正确

nginxnginx -s reload 重新加载配置文件

server {

    listen 8088;

    server_nameadmin.cloud.xxbmm.com;

    root /opt/local/web-cloud;

    index index.html;

    location ~ ^/favicon\.ico$ {

        root /opt/local/web-cloud;

    }

    location / {

        try_files $uri $uri/ @fallback;

        index index.html;

        proxy_set_header   Host             $host;

        proxy_set_header   X-Real-IP        $remote_addr;

        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

        proxy_set_header   X-Forwarded-Proto  $scheme;

    }

    location @fallback {

        rewrite ^.*$ /index.html break;

    }

    access_log  /opt/local/web-cloud/access.log  main;

}

server {

        listen       443 ssl;

    server_namedevadmin.cloud.xxbmm.com;

        root         /opt/local/httpdapp;

        client_max_body_size   50m;

        ssl_certificate "/usr/local/ssl/devadmin_cloud/214906766920830.pem";

        ssl_certificate_key "/usr/local/ssl/devadmin_cloud/214906766920830.key";

        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;

        ssl_ciphers         HIGH:!aNULL:!MD5;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        location ^~ / {

        proxy_passhttp://localhost:8084;

            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 404 /404.html;

            location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

}

你可能感兴趣的:(nginx安装及简单优化)