從零搭建php環境-openresty

參考來源:http://openresty.org/en/insta...php

1、配置編譯參數,使用默認html

> cd /usr/local/src/
> tar -xvf openresty-1.19.3.1.tar.gz
> cd openresty-1.19.3.1
> ./configure -j2

一、Can't locate File/Temp.pm in @INC (you may need to install the File::Temp module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at ./configure line 9.nginx

yum install perl

二、./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.vim

ERROR: failed to run command: sh ./configure --prefix=/usr/local/openresty/nginx ...bash

yum -y install pcre-devel

三、./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.session

ERROR: failed to run command: sh ./configure --prefix=/usr/local/openresty/nginx ...app

yum -y install openssl openssl-devel
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/openresty/nginx"
  nginx binary file: "/usr/local/openresty/nginx/sbin/nginx"
  nginx modules path: "/usr/local/openresty/nginx/modules"
  nginx configuration prefix: "/usr/local/openresty/nginx/conf"
  nginx configuration file: "/usr/local/openresty/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/openresty/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/openresty/nginx/logs/error.log"
  nginx http access log file: "/usr/local/openresty/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

cd ../..
Type the following commands to build and install:
    gmake
    gmake install

2、編譯tcp

gmake
-L/usr/local/src/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -L/usr/local/src/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,--require-defined=pcre_version -Wl,-E -Wl,-E -ldl -lpthread -lcrypt -L/usr/local/src/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl -L/usr/local/src/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/openresty/nginx|" \
    -e "s|%%PID_PATH%%|/usr/local/openresty/nginx/logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/usr/local/openresty/nginx/conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/usr/local/openresty/nginx/logs/error.log|" \
    < docs/man/nginx.8 > objs/nginx.8
gmake[2]: Leaving directory '/usr/local/src/openresty-1.19.3.1/build/nginx-1.19.3'
gmake[1]: Leaving directory '/usr/local/src/openresty-1.19.3.1/build/nginx-1.19.3'

3、安裝ide

gmake install

這裏不知道爲啥跟步驟二返回一致,指南里是分步驟命令,但這裏好像是gmake和gmake install 同時執行了php-fpm

4、使用

從官方的入門使用教程中,感受跟nginx自己單獨安裝並沒有二樣;
nginx默認裝在openresty安裝目錄下;能夠徹底當作一個單獨的nginx,按照之前的經驗使用;

openresty到底加強了nginx什麼,須要在後續使用中發現;
安裝就到此結束

4、使用
一、配置nginx配置文件
咱們可能會建多個項目,所以會用到虛擬主機配置。這裏按常規採用一個主配置,加載多個虛擬主機配置的方式

user  www;
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 {
    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;


    #虛擬主機配置 自動加載
    include /usr/local/openresty/nginx/conf/nginx.conf.vhost/*.conf;


    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  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;
        #    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 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;
    #    }
    #}
}

虛擬主機配置

# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
    charset        utf-8;
    listen        80;
    server_name  blog.54skyer.cn;
    set $root   /home/www/blog.54skyer.cn/public;
    root    $root;
    #root   /home/www/blog.54skyer.cn/public;
    index    index.php index.html;

    # 指定某個目錄能夠被直接訪問
    location /54skyer/ {
        autoindex    on;
    }

    location / {
        # 若是根目錄下匹配不是腳本 默認在根目錄後拼一個index.php 這是爲了在url中省略index.php
        if (!-e $request_filename){
            rewrite ^(.*) /index.php/$1 last;
            break;
        }
    }

    #pathinfo配置 使支持tp5的標準url
    location ~ .+\.php($|/) {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
        include fastcgi_params;
    }

    # 匹配到php擴展名的url
    #location ~\.php$ {
    #    include /usr/local/openresty/nginx/conf/fastcgi.conf;    
    #    fastcgi_intercept_errors on;
    #    #轉發給php-fpm,其端口是9000;
    #    fastcgi_pass 127.0.0.1:9000;
    #}
}


# 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;
#    }
#}

二、配置開機自啓動

> vim /etc/init.d/nginx
# 複製粘貼腳本代碼,保存退出
> chmod a+x /etc/init.d/nginx # 設置可執行權限
> chkconfig --add nginx # 註冊成服務
> chkconfig nginx on # 設置開機自啓動
> reboot # 重啓檢測自否開機自啓動
> ps aux | grep nginx 
#或 netstat -nplt | grep nginx

複製粘貼自啓腳本以下

#! /bin/bash
# Startup script for the nginx Web Server
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve

PATH=/usr/local/openresty/nginx

DESC="nginx daemon"

NAME=nginx

DAEMON=$PATH/sbin/$NAME

CONFIGFILE=$PATH/conf/$NAME.conf

PIDFILE=$PATH/logs/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

set -e
        [ -x "$DAEMON" ] || exit 0
do_start() {
        $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
        $DAEMON -s stop || echo -n "nginx not running"
}

do_reload() {
        $DAEMON -s reload || echo -n "nginx can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;

stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;

reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;

restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;

*)

echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
相關文章
相關標籤/搜索