一、什么是nginx

 Nginx ("engine x") 是一个高性能的HTTP反向代理服务器,也是一个IMAP/POP3/SMTP服务器

二、优点

占有内存少,并发能力强

三、如何用

nginx安装教程:http://www.runoob.com/linux/nginx-install-setup.html

安装过程中肯能遇到的问题:

1)[error] open() "/usr/local/nginx/logs/nginx.pid"

解决方法:[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

2)invalid PID number ""

解决方法:将nginx/conf/nginx.conf配置中的pid /home/djy/public/nginx/nginx/nginx.pid;这一行注释了

3)有时候进程会被占用

查看进程:

ps -ef | grep nginx

杀掉进程:

 

1、删除对应的程序进程即可
 
kill -9 1116

 

2、如果确认就只有nginx占用,也可以直接结束nginx的所有进程

 

killall -9 nginx

 

 

nginx.conf参考:

 1 user 用户名 所属的分组;
 2 worker_processes 2; #设置值和CPU核心数一致
 3 error_log /home/djy/public/nginx/nginx/logs/nginx_error.log crit; #日志位置和日志级别
 4 
 5 #Specifies the value for maximum file descriptors that can be opened by this process.
 6 worker_rlimit_nofile 65535;
 7 events
 8 {
 9   use epoll;
10   worker_connections 65535;
11 }
12 http
13 {
14   include mime.types;
15   default_type application/octet-stream;
16   log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
17                '$status $body_bytes_sent "$http_referer" '
18                '"$http_user_agent" $http_x_forwarded_for';
19 
20 #charset gb2312;
21 
22   server_names_hash_bucket_size 128;
23   client_header_buffer_size 32k;
24   large_client_header_buffers 4 32k;
25   client_max_body_size 8m;
26 
27   sendfile on;
28   tcp_nopush on;
29   keepalive_timeout 60;
30   tcp_nodelay on;
31   fastcgi_connect_timeout 300;
32   fastcgi_send_timeout 300;
33   fastcgi_read_timeout 300;
34   fastcgi_buffer_size 64k;
35   fastcgi_buffers 4 64k;
36   fastcgi_busy_buffers_size 128k;
37   fastcgi_temp_file_write_size 128k;
38   gzip on;
39   gzip_min_length 1k;
40   gzip_buffers 4 16k;
41   gzip_http_version 1.0;
42   gzip_comp_level 2;
43   gzip_types text/plain application/x-javascript text/css application/xml;
44   gzip_vary on;
45 
46   #limit_zone crawler $binary_remote_addr 10m;
47  #下面是server虚拟主机的配置
48  server {
49         listen       80;
50         server_name  localhost;
51 
52             location /resource_static/ {
53             add_header 'Access-Control-Allow-Origin' '*';
54             add_header 'Access-Control-Allow-Credentials' 'true';
55             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
56             add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
57             root   /home/djy/;
58         }
59 
60     }
61 
62 }

 

以上配置完成后,以下两个命令要配合使用才能正常访问:

/home/djy/public/nginx/nginx/sbin/nginx -s reload # 重新载入配置文件
/home/djy/public/nginx/nginx/sbin/nginx -s reopen # 重启 Nginx

四、uploadFile+nginx实现上传图片(Windows/Linux均可用)

参考地址:http://blog.csdn.net/u010191243/article/details/50596793

posted on 2017-03-09 19:31  风又奈何  阅读(247)  评论(0编辑  收藏  举报