使用Nginx配置-404

如何解决使用Nginx配置-404

    /etc/nginx/nginx.conf
    
    user nginx devx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        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  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
    
        upstream backend {
            server  127.0.0.1:3001;
        }
        server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  sitename.com;
        #_;
            root         /opt/sitename/server;
        #/usr/share/nginx/html;
        index        index.html;
        #access_log   /sitename/nginx_logs/access.log;
    
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
        location ~ ^/(images/||javascripts/|fonts/|data/|index.html|robots.txt|humans.txt|favicon.ico) {
            root /opt/sitename/server;
        }
        location /clicked {proxy_pass http://backend;}
            location / {
            proxy_pass  http://backend;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_buffering         on;
            }
    location /s2 { 
        proxy_pass "http://127.0.0.1:3000";
        root /opt/sitename/server/s2;
    }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

}

www.js(服务器)

#!/usr/bin/env node
var app = require('../app');
var debug = require('debug')('sitename:server');
var http = require('http');

var port = normalizePort(process.env.PORT || '3001');
app.set('port',port);
//app.set('hostname','11.111.111.11');
var server = http.createServer(app);
server.listen(port);
server.on('error',onError);
server.on('listening',onListening);
function normalizePort(val) {
  var port = parseInt(val,10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}
function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}
function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}

app.js

   //.....
    const indexRouter = require('./routes/index');
    //.....
    app.use(express.json());
    app.use(express.urlencoded({ extended: false }));
    app.use(cookieParser());
    app.use(stylus.middleware(path.join(__dirname,'public')));
    app.use(express.static(path.join(__dirname,'public')));
    app.use('/',indexRouter);

在我工作的笔记本电脑上,尽管我没有在此处安装nginx,但一切都可以在node.js / express上正常工作。但是在托管服务器上,当我单击带有/ clicked请求的按钮时,显示404错误。实际错误是 scripts.js:1006 POST http://11.111.111.11/clicked 404 (Not Found)

所有文件都在服务器上的一个文件夹中,包括静态文件和节点服务器文件- / opt / sitename / server :/ js,/ css,/ routes等。

js-调用服务器路由功能的脚本:

 button.addEventListener('click',async function (e) {
        await fetch('/clicked',{
            method: 'POST',mode: 'no-cors',url: `http://http://11.111.111.11:3001`,headers: {
                'Content-Type': 'application/text'
            },body: JSON.stringify({test: 'This is just a test',prio: 1})
        })
            .then(res => res.json()).then(jsonData => resp.innerText = jsonData.message);
    });

尝试使用11.111.111.11 ip,localhost,127.0.0.1-完全相同。

日志似乎像预期的那样。 Node.js似乎可以正常工作,我上次甚至在pm2上运行了它。 访问日志: 23.222.22.22--[05 / Oct / 2020:12:24:00 +0000]“ POST / clicked HTTP / 1.1” 404169“ http://22.222.222.22/”“ Mozilla / 5.0(Windows NT 6.2; Win64 ; x64; rv:82.0)Gecko / 20100101 Firefox / 82.0“”-“ 22.222.22.11--[05 / Oct / 2020:12:24:08 +0000]“ POST / auth / facebook / HTTP / 1.1” 404169“ http://11.111.111.11/”“ Mozilla / 5.0(Windows NT 6.2; Win64; x64; rv:82.0)Gecko / 20100101 Firefox / 82.0“”-“

错误日志:

2020/10/05 12:24:00 [错误] 40380#0:* 14 open()“ / opt /站点名称/服务器/已单击”失败(2:无此类文件或目录),客户端:11.111。 11.11,服务器:sitename.com,请求:“ POST / clicked HTTP / 1.1”,主机:“ 11.111.111.11”,引荐来源网址:“ http://11.111.112.21/” 2020/10/05 12:24:08 [错误] 40380#0:* 15找不到“ /opt/sitename/server/auth/facebook/index.html”(2:没有此类文件或目录),客户端: 21.111.33.33,服务器:sitename.com,请求:“ POST / auth / facebook / HTTP / 1.1”,主机:“ 33.333.333.33”,引荐来源网址:“ http://11.111.111.11/”

facebook / index.html根本不应该在那儿-也许我不得不将成功重定向设置为'/'...但这是一个不同的问题

在这里我想让它起作用的问题在哪里?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-