shallow丿ove
Nginx安装
- cd /usr/local/src
- wget http://nginx.org/download/nginx-1.4.7.tar.gz
- tar zxf nginx-1.4.7.tar.gz
- ./configure --prefix=/usr/local/nginx
- make && make install
- vi /etc/init.d/nginx https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.4.7.tar.gz
--2018-01-04 09:31:08-- http://nginx.org/download/nginx-1.4.7.tar.gz
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3, ...
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 769153 (751K) [application/octet-stream]
Saving to: ‘nginx-1.4.7.tar.gz’
100%[======================================================================================>] 769,153 248KB/s in 3.0s
2018-01-04 09:31:12 (248 KB/s) - ‘nginx-1.4.7.tar.gz’ saved [769153/769153]
[root@localhost src]# tar zxf nginx-1.4.7.tar.gz
[root@localhost src]# cd nginx-1.4.7/
[root@localhost nginx-1.4.7]# ./configure --prefix=/usr/local/nginx
checking for OS
+ Linux 3.10.0-123.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for SO_ACCEPTFILTER ... not found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for md5 in system md library ... not found
checking for md5 in system md5 library ... not found
checking for md5 in system OpenSSL crypto library ... found
checking for sha1 in system md library ... not found
checking for sha1 in system OpenSSL crypto library ... found
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/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"
[root@localhost nginx-1.4.7]# make && make install
#
注释:#指定运行权限的用户 --user=nginx #指定运行的权限用户组 --group=nginx #指定安装路径 --prefix=/usr/local/nginx #支持nginx状态查询 --with-http_stub_status_module #开启ssl支持 --with-http_ssl_module #开启GZIP功能 --with-http_gzip_static_module
[root@localhost nginx-1.4.7]# ls /usr/local/nginx/
conf html logs sbin
[root@localhost nginx-1.4.7]# vi /etc/init.d/nginx
1 #!/bin/bash
2 # chkconfig: - 30 21
3 # description: http service.
4 # Source Function Library
5 . /etc/init.d/functions
6 # Nginx Settings
7 NGINX_SBIN="/usr/local/nginx/sbin/nginx"
8 NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
9 NGINX_PID="/usr/local/nginx/logs/nginx.pid"
10 RETVAL=0
11 prog="Nginx"
12 start()
13 {
14 echo -n $"Starting $prog: "
15 mkdir -p /dev/shm/nginx_temp
16 daemon $NGINX_SBIN -c $NGINX_CONF
17 RETVAL=$?
18 echo
19 return $RETVAL
20 }
21 stop()
22 {
23 echo -n $"Stopping $prog: "
24 killproc -p $NGINX_PID $NGINX_SBIN -TERM
25 rm -rf /dev/shm/nginx_temp
26 RETVAL=$?
27 echo
28 return $RETVAL
29 }
30 reload()
31 {
32 echo -n $"Reloading $prog: "
33 killproc -p $NGINX_PID $NGINX_SBIN -HUP
34 RETVAL=$?
35 echo
36 return $RETVAL
37 }
38 restart()
39 {
40 stop
41 start
42 }
43 configtest()
44 {
45 $NGINX_SBIN -c $NGINX_CONF -t
46 return 0
47 }
48 case "$1" in
49 start)
50 start
51 ;;
52 stop)
53 stop
54 ;;
55 reload)
56 reload
57 ;;
58 restart)
59 restart
60 ;;
61 configtest)
62 configtest
63 ;;
64 *)
65 echo $"Usage: $0 {start|stop|reload|restart|configtest}"
66 RETVAL=1
67 esac
68 exit $RETVAL
[root@localhost nginx-1.4.7]# chmod 755 /etc/init.d/nginx
[root@localhost nginx-1.4.7]# chkconfig --add nginx
[root@localhost nginx-1.4.7]# chkconfig nginx on
[root@localhost nginx-1.4.7]# cd /usr/local/nginx/conf/
[root@localhost conf]# mv nginx.conf nginx.conf.1
[root@localhost conf]# vi nginx.conf
1 user nobody nobody;
2 worker_processes 2;
3 error_log /usr/local/nginx/logs/nginx_error.log crit;
4 pid /usr/local/nginx/logs/nginx.pid;
5 worker_rlimit_nofile 51200;
6 events
7 {
8 use epoll;
9 worker_connections 6000;
10 }
11 http
12 {
13 include mime.types;
14 default_type application/octet-stream;
15 server_names_hash_bucket_size 3526;
16 server_names_hash_max_size 4096;
17 log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
18 ' $host "$request_uri" $status'
19 ' "$http_referer" "$http_user_agent"';
20 sendfile on;
21 tcp_nopush on;
22 keepalive_timeout 30;
23 client_header_timeout 3m;
24 client_body_timeout 3m;
25 send_timeout 3m;
26 connection_pool_size 256;
27 client_header_buffer_size 1k;
28 large_client_header_buffers 8 4k;
29 request_pool_size 4k;
30 output_buffers 4 32k;
31 postpone_output 1460;
32 client_max_body_size 10m;
33 client_body_buffer_size 256k;
34 client_body_temp_path /usr/local/nginx/client_body_temp;
35 proxy_temp_path /usr/local/nginx/proxy_temp;
36 fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
37 fastcgi_intercept_errors on;
38 tcp_nodelay on;
39 gzip on;
40 gzip_min_length 1k;
41 gzip_buffers 4 8k;
42 gzip_comp_level 5;
43 gzip_http_version 1.1;
44 gzip_types text/plain application/x-javascript text/css text/htm
45 application/xml;
46 server
47 {
48 listen 80;
49 server_name localhost;
50 index index.html index.htm index.php;
51 root /usr/local/nginx/html;
52 location ~ \.php$
53 {
54 include fastcgi_params;
55 fastcgi_pass unix:/tmp/php-fcgi.sock;
56 fastcgi_index index.php;
57 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
58 }
59 }
60 }
[root@localhost conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost conf]# /etc/init.d/nginx start
Starting nginx (via systemctl): [ OK ]
[root@localhost conf]# ps aux | grep nginx
root 5676 0.0 0.0 24804 784 ? Ss 09:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 5677 0.0 0.1 27108 3364 ? S 09:49 0:00 nginx: worker process
nobody 5678 0.0 0.1 27108 3364 ? S 09:49 0:00 nginx: worker process
root 5682 0.0 0.0 112660 976 pts/0 S+ 09:50 0:00 grep --color=auto nginx
测试
[root@localhost conf]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
ls /usr/local/nginx/html/index.html curl 192.168.9.134
[root@localhost conf]# vi /usr/local/nginx/html/1.php
1 <?php
2 echo "hello ngnix test page!";
[root@localhost conf]# curl localhost/1.php
hello ngnix test page!