`
haoningabc
  • 浏览: 1466120 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx 405 错误解决 (js高亮)

阅读更多
nginx遇到post请求静态文件会得到405错误
用upstream 把post转成get方式


比如高亮代码 code.html, 注意把js高亮的js放到结尾了,先加载html
<html>
<head>
<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" rel="stylesheet" type="text/css"/>
<script src="jquery.min.js" type="text/javascript"></script>
</head>
<body onload='prettyPrint()'>
<script type="text/javascript">
	$.ajax({
	  type: 'POST',
	  url: "a.c",
	  success: function(data){
        alert(data);
        $("#thiscode").html(data);
      },
      error:function(e){
      	alert(e);
      },
	  dataType: "string"
	});
</script>
</script>
<pre class="prettyprint">
public class Demo{
    public static void main(){
    	System.out.println("aa");
    }
}
</pre>
<pre class="prettyprint" id="thiscode">
</pre>
</body>
</html>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js" type="text/javascript"></script> 


添加 nginx.conf
添加
upstream static_backend {
  server localhost:80;
}
server {
....
添加
        error_page 405 =200 @405;
	location @405 {
		root html;
		proxy_method GET;
		proxy_pass http://static_backend;
	}

或者
location / {      
            root   html;      
            index  index.html index.htm index.php;                                                            
            error_page 405 =200 http://$host$request_uri;
        }   

完整的如下:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream static_backend {
        server localhost:80;
    }
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        error_page 405 =200 @405;
	location @405 {
		root html;
		proxy_method GET;
		proxy_pass http://static_backend;
	}
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}



a.c的代码
#include 
#include 
#include 
#include 
#include 

int main(argc,argv){
    int s,len;
    struct sockaddr_in remote_addr;
    char buf[BUFSIZ];
    memset(&remote_addr,0,sizeof(remote_addr));
    remote_addr.sin_family=AF_INET;
    remote_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
    remote_addr.sin_port=htons(8000);
        if((s=socket(AF_INET,SOCK_STREAM,0))<0)
    {
        perror("socket");
        return 1;
    }
    if(connect(s,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr))<0)
    {
        perror("connect");
        return 1;
    }
    printf("connect to server\n");
    len=recv(s,buf,BUFSIZ,0);
    buf[len]='\0';
    printf("%s",buf);
    while(1){
        printf("enter string to end:");
        scanf("%a",buf);
        if(!strcmp(buf,"quit"))
            break;
        len=send(s,buf,strlen(buf),0);
        len=recv(s,buf,strlen(buf),0);
        buf[len]='\0';
        printf(" received:%s\n",buf);
    }
    close(s);
    return 0;
}
分享到:
评论

相关推荐

    toolkit:记录各种工具的使用方法,包括并不限于 Git、Mac、WebStorm、Atom、VS Code、Nginx

    它支持HTML、CSS、JavaScript等前端技术,具备代码高亮、自动完成、错误检查等功能。学习如何配置和使用WebStorm,以及其内置的调试工具,能有效提升前端开发体验。 4. **Atom**:Atom是GitHub推出的一款开源文本...

    基于Node.Js的Markdown博客系统Liblog.zip

    Liblog还支持整站静态网页生成,同时有发布相关的配置,使用nginx做反向代理,动静态资源分离,静态缓存等,使您发布后的博客访问秒开。 二.功能特点 一键导入Markdown文章 文章评论 代码高亮 文章内容...

    php在线编辑器Editone1.4

    4. **错误检查**:Editone1.4具有基础的错误检测能力,能够在编写过程中提醒用户可能存在的语法错误,避免了因小错误导致的大问题。 5. **版本控制**:虽然在描述中未提及,但通常在线编辑器会提供一定的版本管理...

    avue-cli后台模板文档.pdf

    在项目部署方面,文档不仅涵盖了传统的生产打包和部署技术,如使用nginx和tomcat进行服务器部署,还包括了现代的容器化部署解决方案,例如Docker。文档还介绍了如何使用HBuilder进行打包部署,以及如何优化打包性能...

    KODExplorer 芒果云-资源管理器

    - 全平台兼容性:Win Linux Mac (Apache、Nginx、IIS) #### 2.使用场景: - 取代FTP,服务端、客户端软件等复杂的安装配置。kod可以一键安装随处使用. - 你可以用它来管理你的服务器(备份,在线解压缩,版本发布......

    计算机代码.zip

    5. **错误处理和调试**:编写代码的过程中难免会出现错误,学习如何通过异常处理、日志记录以及使用调试工具(如debugger)来定位和解决问题是非常重要的。 6. **算法和数据结构**:理解基本的算法和数据结构(如...

    php开发培训最全学习大纲.docx

    2. 对象在JS中的特殊性:理解JavaScript的对象模型和原型链。 3. 对象回收机制:了解JavaScript的垃圾回收机制。 4. 对象上的成员变量:声明和访问对象属性。 5. 面向对象特性:实现继承、封装和多态。 十二、DOM和...

    PHP论文格式化系统——前台的设计与实现(源代码+论文).zip

    - 错误反馈:将检查结果转化为用户友好的提示,例如用颜色高亮显示错误位置。 5. 安全性与性能优化 - 输入验证:对用户上传的文件进行大小、类型限制,防止恶意文件上传。 - 性能优化:使用缓存技术减少数据库查询...

    PHP简明教程(word文档90页)

    这些工具提供了语法高亮、代码提示等功能,提高编写效率。 2. **服务器软件的安装和配置** 服务器软件如Apache或Nginx是运行PHP所必需的。Apache是常见的选择,它能与PHP良好集成,通过配置文件Apache HTTP Server...

    EclipsePHP Studio 1.2.2 (EPP)

    EclipsePHP Studio集成了对PHP的全面支持,包括语法高亮、代码自动完成、错误检查、调试工具等。这使得开发者能够在单一环境中编写、测试和调试PHP代码。 3. **代码编辑器**: 提供了强大的代码编辑功能,如智能...

    苍穹个人主页源码.zip

    它提供了代码高亮、自动完成等功能,使得代码编写和修改更为便捷。对于初学者,Notepad++ 是一个不错的入门工具,能够帮助理解并编辑HTML源码。 3. **服务器部署**: 用户提到将源码上传至服务器后即可访问。这...

    如何使用Gitblog和Markdown建自己的博客

    如果遇到问题,可以通过错误日志排查配置错误。 Gitblog的主要特点包括: 1. 使用Markdown编写,简化了内容创作。 2. 支持评论、代码高亮、PV统计、LaTeX数学公式等功能。 3. 提供不同主题,允许用户自定义。 4. ...

    1_搭建开发环境.zip

    对于前端开发,可能需要安装Node.js和npm来管理JavaScript依赖,如React、Vue或Angular。 在系统环境中,还需要配置路径变量,确保能从命令行直接运行安装的工具和程序。同时,理解环境变量的概念及其在项目中的...

    netbeans-7.0-ml-php-windows.rar

    1. **PHP支持增强**:7.0版本可能提供了更全面的PHP语法高亮、代码完成、错误检查和快速修复,以提升开发效率。 2. **项目管理**:内置的项目管理器可以帮助开发者组织和管理PHP项目,包括创建新项目、导入现有项目...

    NetBox2.8.rar

    其中,它的代码编辑器支持多种编程语言,如Python、Java、JavaScript等,具备代码高亮、自动完成和错误检查等功能,让编写代码变得更为便捷。 其次,NetBox2.8强调速度。由于互联网应用对响应时间和用户体验的要求...

    netbeans安装文件

    2. **PHP支持**:对于PHP开发者而言,NetBeans提供了智能代码补全、语法高亮、自动格式化、错误检测等功能,极大提高了开发效率。它还支持流行的PHP框架如Symfony、CakePHP、Yii等,以及内容管理系统如WordPress和...

    PHP图书管理系统【源代码】

    4. **错误和异常处理**: 使用try-catch语句处理可能出现的错误和异常,提高程序的健壮性。 5. **安全防护**: 防止SQL注入、XSS攻击等网络安全问题,使用预编译语句、过滤用户输入、输出编码等方式增强安全性。 6. ...

    Html权威指南

    - **获取Node.js**:虽然不是必需,但Node.js对于搭建本地开发环境及运行Node.js服务器端代码非常有用。 - **获取示例代码**:通过书籍配套资源或在线资源获取示例代码,有助于理解和实践HTML5的使用。 #### 初探...

Global site tag (gtag.js) - Google Analytics