Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

reactjs - How can i configure /etc/nginx/sites-available/default

As it stands right now, here is what I have:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
        server_name _;
            location /api {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_connect_timeout 240;
        proxy_send_timeout 240;
        proxy_read_timeout 240;
        send_timeout 240;
    }
        location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

This is following an example from a past professor but I don't imagine it'll work for me. I have http://35.221.40.223/ and I'm trying to connect that to a database. You can see it here http://35.221.40.223/api/list. Right now there is nothing in it because its not letting me post things. I have util.js:

import "isomorphic-fetch"
export function addTime(name,time) {
    return fetch('http://35.221.40.223/api/addtime?name=${name}&time=${time}', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ name, time }) 
    })
}

and App.js:

import React from 'react';
import { addTime } from "./util";
function App() {
  const [name, setName] = React.useState("")
  const [time, setTime] = React.useState("")
  function handleUpdate(evt) {
    setName(evt.target.value);
  }
  function handleUpdateTime(evt) {
    setTime(evt.target.value);
  }
  async function handleAddTime(evt) {
    await addTime(name,time);
  }
  return <div>
    <p><input type='text' value={time} onChange={handleUpdateTime} /></p>
    <p><input type='text' value={name} onChange={handleUpdate} /></p>
    <button className='button-style' onClick={handleAddTime}>Add Time</button>
  </div>
}
export default App;

When I was running on localhost it was allowing me to put things into the database but I'm not sure what to put in my nginx.

edit: I tried adding server_name 35.221.40.223; to no avail

question from:https://stackoverflow.com/questions/65893651/how-can-i-configure-etc-nginx-sites-available-default

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...