ubuntu NGINX + PHP manual install
1. 필요 패키지 설치
1 2 3 |
apt-get install -y php5-fpm php5-cli php5-mcrypt php5-gd php5-mysql apt-get install -y libgd-gd2-noxpm-ocaml libgd-gd2-noxpm-ocaml-dev apt-get install -y libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libgoogle-perftools-dev perl libperl-dev libstring-crc32-perl gcc make |
2.eval_module 다운로드(필요없으신분은 4번과정으로 넘어기시면 됩니다.)
wget http://www.grid.net.ru/nginx/download/nginx_eval_module-1.0.1.tar.gz
3.압축해제후 patch
1 2 3 4 5 6 |
tar zxf nginx_eval_module-1.0.1.tar.gz sed -i -e "/ngx_http_eval_block/,+10 s~^\([^/]*\)\*ecf,\([^/]*\)\(//.*\)\?$~\1\2 //\1*ecf,\2~I" \ -e "/ngx_http_eval_block/,+60 s~\(//[[:blank:]]*\)\?\(ecf[[:blank:]]*=[[:blank:]]*ctx->loc_conf.*\)~// \2~I" \ -e "/ngx_http_eval_block/,+20 s~^\([^/]*\)\*pclcf,\([^/]*\)\(//.*\)\?$~\1\2 //\1*pclcf,\2~I" \ -e "/ngx_http_eval_block/,+60 s~\(//[[:blank:]]*\)\?\(pclcf[[:blank:]]*=[[:blank:]]*pctx->loc_conf.*\)~// \2~I" \ ./nginx_eval_module-1.0.1/ngx_http_eval_module.c |
4.nginx 1.6.2 다운로드
1 2 3 |
wget http://nginx.org/download/nginx-1.6.2.tar.gz tar zxf nginx-1.6.2.tar.gz cd nginx-1.6.2/ |
5.필요 폴더 생성
1 2 3 4 5 6 |
mkdir -p /server/nginx-1.6.2/cache mkdir -p /server/nginx-1.6.2/cache/client_temp mkdir -p /server/nginx-1.6.2/cache/proxy_temp mkdir -p /server/nginx-1.6.2/cache/fastcgi_temp mkdir -p /server/nginx-1.6.2/cache/uwsgi_temp mkdir -p /server/nginx-1.6.2/cache/scgi_temp |
6.링크 연결
1 |
ln -s /server/nginx-1.6.2 /server/nginx |
7. configure 옵션
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
./configure \ --prefix=/server/nginx-1.6.2 \ --pid-path=/server/nginx-1.6.2/run/nginx.pid \ --with-perl_modules_path=/usr/lib/perl/5.18 \ --http-client-body-temp-path=/server/nginx-1.6.2/cache/client_temp \ --http-proxy-temp-path=/server/nginx-1.6.2/cache/proxy_temp \ --http-fastcgi-temp-path=/server/nginx-1.6.2/cache/fastcgi_temp \ --http-uwsgi-temp-path=/server/nginx-1.6.2/cache/uwsgi_temp \ --http-scgi-temp-path=/server/nginx-1.6.2/cache/scgi_temp \ --with-perl=/usr/bin/perl \ --with-http_addition_module \ --with-http_degradation_module \ --with-http_image_filter_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_mp4_module \ --with-http_flv_module \ --with-http_dav_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_secure_link_module \ --with-google_perftools_module \ --add-module=/root/nginx_eval_module-1.0.1 |
nginx_eval_module 모듈이 필요없으시면 –add-module=/root/nginx_eval_module-1.0.1 옵션을 제거합니다.
8.configure 진행과정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
................ Configuration summary + using system PCRE library + using system OpenSSL library + md5: using OpenSSL library + sha1: using OpenSSL library + using system zlib library nginx path prefix: "/server/nginx-1.6.2" nginx binary file: "/server/nginx-1.6.2/sbin/nginx" nginx configuration prefix: "/server/nginx-1.6.2/conf" nginx configuration file: "/server/nginx-1.6.2/conf/nginx.conf" nginx pid file: "/server/nginx-1.6.2/run/nginx.pid" nginx error log file: "/server/nginx-1.6.2/logs/error.log" nginx http access log file: "/server/nginx-1.6.2/logs/access.log" nginx http client request body temporary files: "/server/nginx-1.6.2/cache/client_temp" nginx http proxy temporary files: "/server/nginx-1.6.2/cache/proxy_temp" nginx http fastcgi temporary files: "/server/nginx-1.6.2/cache/fastcgi_temp" nginx http uwsgi temporary files: "/server/nginx-1.6.2/cache/uwsgi_temp" nginx http scgi temporary files: "/server/nginx-1.6.2/cache/scgi_temp" |
9.make
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
make .................. -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lz -lgd -lprofiler make[1]: Leaving directory `/root/nginx-1.6.2' make -f objs/Makefile manpage make[1]: Entering directory `/root/nginx-1.6.2' sed -e "s|%%PREFIX%%|/server/nginx-1.6.2|" \ -e "s|%%PID_PATH%%|/server/nginx-1.6.2/run/nginx.pid|" \ -e "s|%%CONF_PATH%%|/server/nginx-1.6.2/conf/nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/server/nginx-1.6.2/logs/error.log|" \ < man/nginx.8 > objs/nginx.8 make[1]: Leaving directory `/root/nginx-1.6.2' |
10.make install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
make install make -f objs/Makefile install make[1]: Entering directory `/root/nginx-1.6.2' test -d '/server/nginx-1.6.2' || mkdir -p '/server/nginx-1.6.2' test -d '/server/nginx-1.6.2/sbin' || mkdir -p '/server/nginx-1.6.2/sbin' test ! -f '/server/nginx-1.6.2/sbin/nginx' || mv '/server/nginx-1.6.2/sbin/nginx' '/server/nginx-1.6.2/sbin/nginx.old' cp objs/nginx '/server/nginx-1.6.2/sbin/nginx' test -d '/server/nginx-1.6.2/conf' || mkdir -p '/server/nginx-1.6.2/conf' cp conf/koi-win '/server/nginx-1.6.2/conf' cp conf/koi-utf '/server/nginx-1.6.2/conf' cp conf/win-utf '/server/nginx-1.6.2/conf' test -f '/server/nginx-1.6.2/conf/mime.types' || cp conf/mime.types '/server/nginx-1.6.2/conf' cp conf/mime.types '/server/nginx-1.6.2/conf/mime.types.default' test -f '/server/nginx-1.6.2/conf/fastcgi_params' || cp conf/fastcgi_params '/server/nginx-1.6.2/conf' cp conf/fastcgi_params '/server/nginx-1.6.2/conf/fastcgi_params.default' test -f '/server/nginx-1.6.2/conf/fastcgi.conf' || cp conf/fastcgi.conf '/server/nginx-1.6.2/conf' cp conf/fastcgi.conf '/server/nginx-1.6.2/conf/fastcgi.conf.default' test -f '/server/nginx-1.6.2/conf/uwsgi_params' || cp conf/uwsgi_params '/server/nginx-1.6.2/conf' cp conf/uwsgi_params '/server/nginx-1.6.2/conf/uwsgi_params.default' test -f '/server/nginx-1.6.2/conf/scgi_params' || cp conf/scgi_params '/server/nginx-1.6.2/conf' cp conf/scgi_params '/server/nginx-1.6.2/conf/scgi_params.default' test -f '/server/nginx-1.6.2/conf/nginx.conf' || cp conf/nginx.conf '/server/nginx-1.6.2/conf/nginx.conf' cp conf/nginx.conf '/server/nginx-1.6.2/conf/nginx.conf.default' test -d '/server/nginx-1.6.2/run' || mkdir -p '/server/nginx-1.6.2/run' test -d '/server/nginx-1.6.2/logs' || mkdir -p '/server/nginx-1.6.2/logs' test -d '/server/nginx-1.6.2/html' || cp -R html '/server/nginx-1.6.2' test -d '/server/nginx-1.6.2/logs' || mkdir -p '/server/nginx-1.6.2/logs' make[1]: Leaving directory `/root/nginx-1.6.2' |
11. nginx.conf 백업
1 |
mv /server/nginx/conf/nginx.conf /server/nginx/conf/nginx.conf.org |
12. vi /server/nginx/conf/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
user www-data www-data; worker_processes 1; worker_rlimit_nofile 100000; worker_rlimit_sigpending 10000; error_log /server/nginx/logs/error.log; pid /server/nginx/run/nginx.pid; events { worker_connections 1024; accept_mutex_delay 100ms; multi_accept on; use epoll; } http { #---------------------------------------------------------------------------------------# #--- default ---------------------------------------------------------------------------# #---------------------------------------------------------------------------------------# include mime.types; sendfile on; tcp_nopush on; gzip on; tcp_nodelay on; keepalive_timeout 30; keepalive_requests 100000; send_timeout 2; server_tokens off; server_name_in_redirect off; default_type application/octet-stream; index index.html #---------------------------------------------------------------------------------------# #--- time ------------------------------------------------------------------------------# #---------------------------------------------------------------------------------------# client_body_timeout 10; client_header_timeout 10; #---------------------------------------------------------------------------------------# #--- proxy -----------------------------------------------------------------------------# #---------------------------------------------------------------------------------------# 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 120; proxy_read_timeout 300; proxy_buffers 32 32k; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; proxy_ignore_client_abort on; proxy_cache_path /server/nginx/cache/one levels=1:2 keys_zone=one:10m max_size=1500m inactive=600m; proxy_cache_key "$scheme$host$request_uri"; proxy_temp_path /server/nginx/cache/tmp; #---------------------------------------------------------------------------------------# #--- log -------------------------------------------------------------------------------# #---------------------------------------------------------------------------------------# log_format main '$remote_addr - $remote_user [$time_local-$msec] $status ' '"$request" $request_time $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #---------------------------------------------------------------------------------------# #--- - http ----------------------------------------------------------------------------# #---------------------------------------------------------------------------------------# server { listen 80; server_name localhost; charset utf-8; access_log /server/nginx/logs/access.log main; location / { root html; index index.html index.htm; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include mime.types; } } } |
12.PHP 보안관련 및 적용
1 2 3 4 |
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php5/fpm/php.ini service php5-fpm restart |
13.phpinfo.php 생성
1 2 3 4 5 6 7 |
touch /server/nginx/html/phpinfo.php vi /server/nginx/html/phpinfo.php <? phpinfo(); ?> |
14. 폴더 권한설정
1 2 |
chown -R www-data:www-data /server/nginx-1.6.2 chown -R www-data:www-data /server/nginx |
15. nginx start script 생성
1 2 |
touch /etc/init.d/nginx chmod a+x /etc/init.d/nginx |
vi /etc/init.d/nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#!/bin/bash # # description: Starts and stops the Nginx Server # nginx Service script for Linux start() { su -c "/server/nginx/sbin/nginx" } stop() { su -c "/server/nginx/sbin/nginx -s stop" } reload() { su -c "/server/nginx/sbin/nginx -s reload" } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop sleep 2 start ;; *) echo $" Usage {start|stop|restart|reload}" exit 1 esac |
16.서버기동시 자동스크립트 등록
1 |
update-rc.d nginx defaults |
17. brower 실행후 URL확인
http://