我问的是如何配置nginx。现在我尝试了一些变体并在此基础上叠加:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /srv/appfolder/build;
index index.html;
server_name my_server_ip_without_http;
location / {
try_files $uri $uri/ =404;
}
}
~
现在-当我访问我得到的服务器 IP 时:
Welcome to nginx!
目前我只尝试使用 http 作为开始。 是否可以使其以 IP:port/pagename 格式工作?或IP:页面名称? 是否可以在不同端口上提供多个应用程序并启用应用程序页面 uri 工作?
最佳答案
您将不得不使用 react-router ,另外配置您的 .htaccess 以兼容。示例:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
关于reactjs - 如何在没有域名(仅 IP)的服务器上使用 nginx 服务 react-create-app 构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52603532/