nginx在centos下的安裝

常用軟體,程式語言的筆記和疑問
Forum rules
盡量做到:
每一個貼子都精心編輯;
每一個疑問都得到解答。
Post Reply
ejsoon
Site Admin
Posts: 3919
Joined: 2016 Jan 10, 22:15

nginx在centos下的安裝

Post by ejsoon » 2017 Apr 07, 11:59

03-php

Code: Select all

yum list installed | grep php
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
rpm -Uvh http://mirrors.hust.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
yum install libmcrypt-devel
yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64
yum install php55w-fpm
yum install  php55w-xml php55w-xmlrpc
04-nginx

Code: Select all

wget -O nginx-1.10.1.tar.gz http://nginx.org/download/nginx-1.10.1.tar.gz

(解壓,cd至某一路徑)

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

yum install gcc
yum install gcc-c++
yum -y install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel

(重新configure)

make && make install


vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL


chmod a+x /etc/init.d/nginx




#new#
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/soft/ngx_http_substitutions_filter_module
make && make install
05.nginx-php

Code: Select all

/usr/sbin/php-fpm -t
service php-fpm start
chkconfig php-fpm on
ps aux |grep php-fpm
netstat -ant |grep 9000
06-php_redis

Code: Select all

wget -O phpredis-2.2.7.tar.gz https://github.com/phpredis/phpredis/archive/2.2.7.tar.gz
yum install php55w-devel

获取产品授权 
phpize
./configure --with-php-config=/usr/bin/php-config
make
make install

 vi /etc/php.ini 
extension=redis.so
date.timezone = "Asia/Shanghai"

service php-fpm restart
07-redis

Code: Select all

wget -O redis-3.2.3.tar.gz http://download.redis.io/releases/redis-3.2.3.tar.gz
make

make PREFIX=/usr/local/redis install
cp ./redis.conf /usr/local/redis/
vim /usr/local/redis/redis.conf
daemonize yes #redis将以守护进程的方式运行,默认为no会暂用你的终端
timeout 300​ #当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
#src/redis-server

vim /etc/init.d/redis

#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
        if [ -e $PIDFILE ];then
             echo "$desc already running...."
             exit 1
        fi
        echo -n $"Starting $desc: "
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $"Stop $desc: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL

chmod 777 /etc/init.d/redis


service redis start
service redis stop
08-php-nginx

Code: Select all

修改php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
;listen = 127.0.0.1:9000
listen = /dev/shm/php-cgi.sock
修改nginx配置文件server段的配置,将http的方式改为socket方式
location ~ [^/]\.php(/|$) {
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
}

##以上不一定要運行##



重启php-fpm与nginx
service nginx restart
service php-fpm restart
ls -al /dev/shm


listen.owner = www-data
listen.group = www-data
listen.mode = 0660

ejsoon
Site Admin
Posts: 3919
Joined: 2016 Jan 10, 22:15

MySQL在centos下的安裝

Post by ejsoon » 2017 Apr 07, 12:01

1.添加MySQL Yum资源库
wget http://dev.mysql.com/get/mysql57-commun ... noarch.rpm

rpm -Uvh mysql57-community-release-el6-8.noarch.rpm
2.选择一个发行版系列
yum repolist all | grep mysql

vi /etc/yum.repos.d/mysql-community.repo


yum repolist enabled | grep mysql
3.安装MySQL
yum install mysql-community-server

4.启动MySQL服务器
service mysqld start
service mysqld status

mysql_secure_installation 默认密码为空
mysqld
character_set_server=utf8
lower_case_table_names=1

ejsoon
Site Admin
Posts: 3919
Joined: 2016 Jan 10, 22:15

解決redis不能用

Post by ejsoon » 2017 Apr 11, 09:39

Code: Select all

/usr/local/redis/bin/redis-cli
127.0.0.1:6379> flushall
一個應用實例:

Code: Select all

        if (!$this->cache->redis->exists("menu:" . $pid)) {
            $this->db->from("menu");
            $this->db->where("pid", $pid);
            $this->db->order_by("id", "ASC");
            $query = $this->db->get();
            $menus = $query->result_array();
            $this->cache->redis->save("menu:" . $pid, $menus, 0);
        }else{
            $menus = $this->cache->redis->get("menu:" . $pid);
        }

ejsoon
Site Admin
Posts: 3919
Joined: 2016 Jan 10, 22:15

nginx配個php路徑

Post by ejsoon » 2017 Apr 13, 10:13

Code: Select all

server {
    listen 80;
    server_name help.qchouses.com;

    location ^~ / {
        root /var/www/help;
    }

    location ~ \.php$ {
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_param HTTPS $https if_not_empty;
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

                include fastcgi_params;
    }

}

ejsoon
Site Admin
Posts: 3919
Joined: 2016 Jan 10, 22:15

add nginx location

Post by ejsoon » 2018 Apr 13, 13:31

Code: Select all

location /vuedist {
	alias /home/ejsoon/Documents/practise/vue20180322/vue20180322/dist;
	index index.html index.htm;
}
Note that it may look similar to the root directive at first sight, but the document root doesn't change, just the file system path used for the request. The location part of the request is dropped in the request Nginx issues.
from here

ejsoon
Site Admin
Posts: 3919
Joined: 2016 Jan 10, 22:15

nginx php的session不能用

Post by ejsoon » 2018 Nov 04, 19:05

來自這裡

其實在搜到這篇文章以前我就差不多知道可能是session目錄沒有讀取權限的問題。也沒有用文章的方法,而是直接777:
sudo chmod 777 /var/lib/php/session/

Post Reply