centos6.5安裝nginx-1.8.0,nginx-1.8.0

來源:互聯網
上載者:User

centos6.5安裝nginx-1.8.0,nginx-1.8.0

1.Nginx安裝環境:

  gcc: 安裝nginx需要先將官網下載的源碼進行編譯,編譯依賴gcc環境,如果沒有gcc環境,需要安裝gcc:yum install gcc-c++

  pcre:PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 相容的Regex庫。nginx的http模組使用pcre來解析Regex,所以需要在linux上安裝pcre庫。yum install -y pcre pcre-devel (註:pcre-devel是使用pcre開發的一個二次開發庫。nginx也需要此庫。)

  zlib:zlib庫提供了很多種壓縮和解壓縮的方式,nginx使用zlib對http包的內容進行gzip,所以需要在linux上安裝zlib庫。yum install -y zlib zlib-devel

  openssl:OpenSSL 是一個強大的安全通訊端層密碼庫,囊括主要的密碼演算法、常用的密鑰和認證封裝管理功能及SSL協議,並提供豐富的應用程式供測試或其它目的使用。nginx不僅支援http協議,還支援https(即在ssl協議上傳輸http),所以需要在linux安裝openssl庫。yum install -y openssl openssl-devel

2.清除系統中的httpd痕迹:
  yum remove httpd
  rm -rvf /etc/httpd

3.建立www使用者和使用者組:
groupadd www
useradd -s /sbin/nologin -g www www

5.解壓、配置、編譯、安裝nginx:
tar zxvf nginx-1.8.0.tar.gz -C /usr/src/
cd /usr/src/nginx-1.8.0/
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-mail \
--with-mail_ssl_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_sub_module \
--with-http_spdy_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
make && make install

6.編輯nginx.conf設定檔:
vim /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes auto;
pid /home/www/pid/nginx.pid;
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }
http
    {
        include mime.types;
        default_type application/octet-stream;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
        sendfile on;
        tcp_nopush on;
        keepalive_timeout 60;
        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
      
        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 application/xml;
        gzip_vary on;
        gzip_proxied expired no-cache no-store private auth;
        gzip_disable "MSIE [1-6]\.";

        server_tokens off;
        log_format access '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" $http_x_forwarded_for';
    server
        {
            listen 80 default;
            server_name 127.0.0.1;
            access_log /home/www/log/access.log access;
            error_log /home/www/log/error.log error;
            index index.html index.htm index.php;
            root /home/www/html/;
            error_page 404 /404.html;

            location ~ [^/]\.php(/|$)
            {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
            }
            location /nginx_status
            {
                stub_status on;
                access_log off;
            }
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires 30d;
            }
            location ~ .*\.(js|css)?$
            {
                expires 12h;
            }
        }
    include vhost/*.conf;
    }
7.建立目錄並修改許可權:
mkdir -p /home/www/log
mkdir -p /home/www/pid
mkdir -p /home/www/html
chown -R www:www /home/www/log
chown -R www:www /home/www/pid
chown -R www:www /home/www/html
chown -R www:www /usr/local/nginx

8.測試啟動Nginx

./nginx

9.建立測試頁面和錯誤頁面,並賦予許可權:
touch /home/www/html/index.html
cat>/home/www/html/index.html<<EOF
This is the test Page for Nginx !!!
EOF
touch /home/www/html/404.html
cat>/home/www/html/404.html<<EOF
Error Page for Nginx !!!
EOF
chown -R www:www /home/www/html

10.測試:
http://localhost/
http://localhost/error

11.防火牆開啟80連接埠:

vim /etc/sysconfig/iptablse.conf
添加 -A INPUT -p tcp --dport 80 -j ACCEPT

12.重啟防火牆

service iptables restart

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.