安裝配置nginx

yum -y install gcc automake autoconf libtool make

yum -y install gcc gcc-c++


先安裝pcre, zlib,前者爲了重寫rewrite,後者爲了gzip壓縮。

1.選定源碼目錄
可以是任何目錄,這裏選定的是/usr/local/src

cd  /usr/local/src


2.安裝PCRE庫
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下載最新的 PCRE 源碼包

tar -zxvf pcre-8.38.tar.gz

cd pcre-8.38

./configure

make
make install


3.安裝zlib庫

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.安裝ssl(如果默認沒裝ssl)  
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz

cd openssl-1.0.2g

./config
make
make install


5.安裝nginx1.8.1


yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel


groupadd nginx

useradd -g nginx -s /sbin/nologin nginx


tar zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1


./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_dav_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.38

make

make install


編輯主配置文件nginx.conf


cd /usr/local/nginx/conf


vi nginx.conf


#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;


events {
    use epoll;
    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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       88;
        server_name  mcs.vcfilm.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /mcs/portal/web;
            index  index.php index.html index.htm;
        }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    server {
        listen       88;
        #listen       somename:8080;
        server_name  www.jiashenzhen.com;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

主要修改端口 listen       88;
虛擬域名server_name  mcs.vcfilm.cn;
網頁路徑root   /mcs/portal/web;
頭文件  index  index.php index.html index.htm;


添加php端口

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


改完之後啓動nginx


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


看下進程       ps -ef | grep nginx

看下端口      netstat -nltp | grep nginx












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