1. 程式人生 > >04-nginx伺服器的安裝,redis安裝,前端部署

04-nginx伺服器的安裝,redis安裝,前端部署

nginx伺服器的安裝

    wget http://nginx.org/download/nginx-1.10.0.tar.gz
tar -xvf nginx-1.10.0.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
tar -xvf ngx_cache_purge-2.3.tar.gz
groupadd -r nginx
adduser -r -d /var/cache/nginx -s /sbin/nologin -g nginx nginx
yum -y install zlib zlib-devel openssl openssl-devel
pcre pcre-devel PRGDIR=`pwd` cd nginx-1.10.0 ./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --modules-path=/usr/lib/nginx/modules \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/run/nginx.pid \ --lock-path=/run/nginx.
lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --with-http_ssl_module
\ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-threads \ --with-stream \ --with-stream_ssl_module \ --with-http_slice_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-http_v2_module \ --with-ipv6 \ --add-module=$PRGDIR/ngx_cache_purge-2.3 make sudo make install rm -rf /etc/nginx/html/ mkdir -p /etc/nginx/conf.d/ /usr/share/nginx/html/ install -m644 html/index.html /usr/share/nginx/html/ install -m644 html/50x.html /usr/share/nginx/html/

nginx -t
可以檢視nginx伺服器的配置檔案的語法是否正確,
也可以看到nginx配置檔案的地址。

nginx -c nginx.conf 指定配置檔案的地址

nginx -s reload 重啟nginx伺服器,在修改了配置檔案之後。
nginx -s stop 停止nginx伺服器
nginx -s start 啟動nginx伺服器

nginx 配置檔案

  #宣告使用者為nobody
user nobody;

#開啟nginx工作程序數,一般為1
#可以通過ps -ef | grep nginx 檢視到有4個工作程序
worker_processes 4;

#設定併發數
events{
        #設定最大併發數
        worker_connections 1024;
}

http{
    upstream bro-prj{
         server  localhost:8080;
    }
 include       mime.types;
    default_type  application/octet-stream;
    server {
     listen       80;
    server_name  118.190.159.49;
    charset utf-8;

    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    location = / {
        root   /opt/bro-prj/www;
        index  index.html index.htm;
    }

    location = /index {
        root          /opt/bro-prj/www;
        rewrite ^(.*) /;
    }

    location ~ .*\.(html)$ {
        root   /opt/bro-prj/www;
        index  index.html index.htm;
    }

    location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|woff|woff2|svg|ttf)$ {
        root   /opt/bro-prj/www;
        index  index.html index.htm;
    }

    location ~ .*(css)$ {
        root   /opt/bro-prj/www;
        index  index.html index.htm;
    }

    location ~ /script/(user|role|syslog|wordbooks)\.js$ {
        proxy_pass http://bro-prj;
        proxy_set_header Host $host:$server_port;
    }

    location = /script/wordbooks.js {
        proxy_pass http://bro-prj;
        proxy_set_header Host $host:$server_port;
    }

    location / {
        proxy_pass http://bro-prj;
        proxy_set_header Host $host:$server_port;
    }

}
}

安裝redis

安裝gcc

yum -y install gcc gcc-c++ kernel-devel

    安裝配置redis

sudo groupadd -r redis
sudo adduser -r -s /sbin/nologin -g redis redis
mkdir -p /opt/redis/db
chown -R redis:redis /opt/redis
cd ~
wget http://download.redis.io/releases/redis-3.2.2.tar.gz
tar -xzvf redis-3.2.2.tar.gz
cd redis-3.2.2
make
sudo make install
sudo mkdir -p /usr/local/etc/redis
sudo cp redis.conf /usr/local/etc/redis/
ipaddr=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -E '^(192|172|10)\.'`
sudo sed -i "s/bind 127.0.0.1/bind 127.0.0.1 $ipaddr/" /usr/local/etc/redis/redis.conf
nohup redis-server /usr/local/etc/redis/redis.conf &

驗證,檢視redis的程序
ps -ef | grep redis

前臺部署

  1. build構建html頁面
  2. 將build下面的html頁面複製出來
  3. 將公共的pub裡面的html頁面cp替換伺服器上面的檔案

ps: 可能出現的問題

Resource interpreted as stylesheet but transferred with MIME type text/html (seems not related with web server)


去掉rel=”stylesheet”
再還原一下,當時就是這樣解決的,也不知道是什麼原因呢。