centos6中安裝nginx1.9.3

  1. 安裝說明php

    系統環境:CentOS-6.3html

    軟件:nginx-1.9.3.tar.gznginx

    安裝方式:源碼編譯安裝 c++

    安裝位置:/usr/local/nginx apache

    下載地址:http://nginx.org/en/download.htmlubuntu

  2. 安裝依賴瀏覽器

    yum install gcc-c++服務器

    yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel session

  3. 下載nginx-1.9.3.tar.gzapp

    wget  http://nginx.org/download/nginx-1.9.3.tar.gz 

  4. 安裝

    find -name nginx

    yum remove nginx

    cd /usr/local/src

    tar -zxvf nginx-1.9.3.tar.gz -C ..

    cd /usr/local/nginx-1.9.3

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

    make

    make install

  5. 配置防火牆

    vi /etc/sysconfig/iptables

    #添加配置

      -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

     重啓防火牆

     service iptables restart 

  6. 啓動與測試

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

  7. 若是安裝了httpd會佔用80端口,能夠中止apache,經過命令:service httpd stop

  8. 訪問輸入ip

     

  9. 中止

    #查詢nginx主進程號 

    ps -ef | grep nginx

    #中止進程 

    kill -QUIT 主進程號 

    #快速中止 

    kill -TERM 主進程號 

    #強制中止 

    pkill -9 nginx

    重啓

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

    #測試端口 

    netstat –na|grep 80

    #瀏覽器中測試 

    http://ip:80

 

nginx配置

conf/proxy.conf

proxy_redirect          off;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   300;
proxy_send_timeout      300;
proxy_read_timeout      300;
proxy_buffer_size       4k;
proxy_buffers           4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

conf/nginx.conf

user  root root; # Nginx所在的用戶和用戶組

worker_processes  3; # 啓動的工做進程數量

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

pid        logs/nginx.pid; # Nginx進程ID


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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream localhost { # 發到localhost上的請求,經過Nginx轉發到實際處理請求的服務器
           server 192.168.0.181:8080 weight=1;
           server 192.168.0.184:8080 weight=1;
    }

    server {
        listen       8888; # Nginx監聽的端口,默認爲80
        server_name  localhost; # Nginx所在主機的名稱

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/solr; # 請求資源的路徑(代理:/home/shirdrn/servers/nginx/tml/solr/,該目錄下沒有任何數據)
            index  index.html index.htm;
            proxy_pass   http://localhost; # 代理:對發送到localhost上請求進行代理
            include proxy.conf; # 引入proxy.conf配置
        }

        #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;
        #    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       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


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

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

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

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

}

啓動nginx

# /usr/local/nginx/sbin/nginx

指定配置文件啓動

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

能夠查看啓動進程

root@dev2:~$ ps -ef | grep nginx
root     15952     1  0 18:56 ?        00:00:00 nginx: master process sbin/nginx
root     15953 15952  0 18:56 ?        00:00:00 nginx: worker process
root     15954 15952  0 18:56 ?        00:00:00 nginx: worker process
root     15955 15952  0 18:56 ?        00:00:00 nginx: worker process
ubuntu   22988 22887  0 22:19 pts/0    00:00:00 grep --color=auto nginx

查看Nginx監聽的端口號

root@dev2:/home/ubuntu# netstat -nap | grep '8888'
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      15952/nginx
相關文章
相關標籤/搜索