Home > database >  MEAN NGINX restart server when trying to save file
MEAN NGINX restart server when trying to save file

Time:01-29

I have a MEAN application, in Node I use multer to store files. My configuration file:

   server {
  listen 80 default_server;
  listen [::]:80;
  server_name _;

  location / {
    root /opt/front-end/;
    try_files $uri /index.html;
  }

  location /api {
    proxy_pass http://localhost:4000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_temp_file_write_size 664k;
    proxy_connect_timeout 10080s;
    proxy_send_timeout 10080;
    proxy_read_timeout 10080;
    proxy_buffer_size 16k;
    proxy_buffers 18 32k;
    proxy_busy_buffers_size 224k;
    proxy_redirect off;
    proxy_request_buffering off;
    proxy_buffering off;
  }

  location /images {
    alias /opt/back-end/images/;
  }
}

In NODE my app.js:

const app = express();

mongoose
  .connect(
    "connection"
  )
  .then(() => {
    console.log("Connected to database!");
  })
  .catch(() => {
    console.log("Connection failed!");
  });

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/images", express.static(path.join("images")));

app.use((req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept, Authorization"
  );
  res.setHeader(
    "Access-Control-Allow-Methods",
    "GET, POST, PATCH, PUT, DELETE, OPTIONS"
  );
  next();
});

app.use("/api/user", userRoutes);
app.use("/api/user-profile", userProfileRoutes);

module.exports = app;

From log in NGINX when trying to save file: enter image description here

Permissions to images folder => drwxrwxrwx 2 root root

Does anyone have an idea where is the problem or what I missed? I will be grateful for your help.

CodePudding user response:

The issue was simple to solve but hard to find.

This command solved the problem: sudo pm2 restart name_your_app --watch

As it turned out if we have watching - anabled server detect changes and restart server each time and causes that weird error: Change detected on path...

  • Related