Nginx服務器安裝

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/aojianmo2012/article/details/55189323

安裝nginx1.11

1. 安裝前的準備

yum install gcc gcc-c++  openssl openssl-devel libxml2-devel libevent-devel cmake ncurses-devel autoconf libwebp-devel libjpeg-devel libpng-devel libz-devel libXpm-devel libevent-devel unzip zip
-----------------------------------
顯示行號
:set  nu    
:set  nonu    

顏色開關
:syntax  off
:syntax  on

vi配置文件
    Vi ~/.vimrc  手工建立的,vi配置文件

2. 安裝PCRE庫

cd ~
    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
    或者(第三方):wget https://fossies.org/linux/misc/pcre-8.39.tar.gz
    tar -zxvf pcre-8.39.tar.gz
    cd pcre-8.39
    ./configure
    make
    make install

3. 安裝zlib庫

cd ~
    wget http://zlib.net/zlib-1.2.8.tar.gz
    tar -zxvf zlib-1.2.8.tar.gz
    cd zlib-1.2.8
    ./configure
    make
    make install

4. 安裝openssl

cd ~
    wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
    tar -zxvf openssl-1.0.1t.tar.gz
    ./config
    make
    make install

    openssl version

5. 安裝nginx

cd ~
    wget http://nginx.org/download/nginx-1.11.8.tar.gz
    tar -zxvf nginx-1.11.8.tar.gz
    cd nginx-1.11.8
    ./configure \
    --prefix=/usr/local/nginx-1.11.8 \
    --with-pcre=../pcre-8.39 \
    --with-zlib=../zlib-1.2.8 \
    --with-openssl=../openssl-1.0.1t \
    --with-http_ssl_module \
    make
    make install
[防火牆CentOS6.X]
通過80端口,啓動nginx
    netstat -ano|grep 80
    /usr/local/nginx-1.11.8/sbin/nginx
    iptables -t filter -A INPUT -p tcp -j ACCEPT
    /usr/local/nginx-1.11.8/nginx -s stop
    /usr/local/nginx-1.11.8/nginx

6. 防火牆CentOS7.X

參考https://www.zhaokeli.com/Article/6321.html
    通過80端口,啓動nginx
    yum install firewalld
    systemctl start firewalld
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    systemctl restart firewalld.service
    /usr/local/nginx-1.11.8/sbin/nginx

7. nginx開機啓動

vim /etc/rc.local
    /usr/local/nginx-1.11.8/sbin/nginx
    ESC
    :wq
    chmod +x /etc/rc.d/rc.local

8. nginx1.11.8操作

/usr/local/nginx-1.11.8/nginx -s reload 重載配置
    /usr/local/nginx-1.11.8/nginx -s reopen 重載日誌
    /usr/local/nginx-1.11.8/nginx -s stop   強制關閉

9.nginx.conf配置文件:

#user  nobody;
#worker_processes  1;
worker_processes auto;
worker_cpu_affinity auto;

error_log  /www/logs/nginx_error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

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"';
    #關閉目錄瀏覽:
    #autoindex off;

    access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    server_tokens off;

    keepalive_timeout  65;

    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types  text/plain
                text/css
                application/xml
                application/json
                text/javascript
                application/javascript;
    gzip_vary on;

    ####
    server {
        listen       80;
        server_name  note.swread.com;

        location / {
             root   /www/html;
             index  index.html index.htm index.php;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root   /www/html;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
        error_log /www/logs/error.log;
        access_log /www/logs/access.log;
    }


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章