Nginx学习之反向代理

配置静态网站

server {
        listen       80;
        server_name  localhost;
        location /{
            root    html; #默认Nginx站点
            index  index.html index.htm;
        }
        location ^~ /itstyle/{
            alias    /www/itstyle/; #自定义站点,注意都是以斜杠结尾 文件路径自定义不一定是itstyle
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
              root   html;
        }

配置动态网站

配置JSP

 server {
        listen       80;
        server_name  blog.52itstyle.com;
        location / {
            index  index.jsp;
            #Tomcat访问地址
            proxy_pass http://127.0.0.1:8080; 
        }
        location /solr {
             #类似虚拟目录 指向一个具体项目
             proxy_pass http://127.0.0.1:8180$request_uri;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

配置PHP

server{
        listen 80;
        server_name 52itstyle.com www.52itstyle.com;
        root /mnt/www/domains/52itstyle.com/public_html;
        index index.php index.html;
        error_page  404 = http://www.52itstyle.com/404.html;
 location = /500.html {
        root   /usr/share/nginx/html;
 }
       location ~ \.php$ {
           fastcgi_pass 127.0.0.1:9000;
           include        fastcgi_params;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           access_log     /usr/local/nginx/logs/52itstyle.com.access.log main;#日志
      }
      location ~ /\.ht {
           deny  all;#拒绝访问htaccess文件
      }
}
上一篇:重构——43添加参数(Add Parameter)


下一篇:基于jquery的上传插件Uploadify 3.1.1在MVC3中的使用