Nginx日记
2015-11-03 14:33
489 查看
一.YUM安装Nginx系统:CentOS release 6.6 (Final)创建
/etc/yum.repos.d/nginx.repo 这个文件,内容为:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1
yum install nginx
二.源码安装
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=../pcre-4.4 --with-zlib=../zlib-1.1.3
三.Nginx启动和停止
关闭重启nginx时,需加上-s选项平滑重启关闭
nginx -s signalWhere signal may be one of the following:
stop— 快速关闭
quit— 正常关闭
reload— 重新加载配置文件
reopen— 打开日志文件四.配置文件
配置一般有两个模块
http{
server{
}
}
http {
server {location / {root /data/www;}location /images/ {root /data;}}}
代理配置
server {location / {proxy_pass http://localhost:8080; }location /images/ {root /data;}}
server {listen 8080;root /data/up1;location / {}}
图片路径配置
location ~ \.(gif|jpg|png)$ {root /data/images;}
配置fastcgi代理
server {location / {fastcgi_pass localhost:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param QUERY_STRING $query_string;}location ~ \.(gif|jpg|png)$ {root /data/images;}}
配置支持PHP
location ~ [^/]\.php(/|$){ try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param HTTPS $https if_not_empty;fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name;}
重写URL配置
location /users/ {rewrite ^/users/(.*)$ /show?user=$1 break;}
server {...rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;return 403;...}Nginx错误处理
error_page 404 /404.html;
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- web 应用中常用的各种 cache详解
- Linux系统上配置Nginx+Ruby on Rails+MySQL超攻略
- window+nginx+php环境配置 附配置搭配说明
- 解析CI即CodeIgniter框架在Nginx下的重写规则
- 将PHP从5.3.28升级到5.3.29时Nginx出现502错误
- 基于Nginx0.8.54+PHP5.3.4+MySQL5.5.8的全新LNMP稳定版架构搭建的VPS
- Nginx(PHP/fastcgi)的PATH_INFO问题