问题描述
我的ASP.NET Core APIs
上有一个非常特殊的案例Linux
。
我有两个environments
- PROD-https://somesite.com-用户界面及其API端点-https://somesite.com/api
- DEV-https://somesite-dev.com-用户界面及其API端点-https://somesite-dev.com/api
两个UI均由{{1}上的Nginx
提供服务,并且它们各自的API使用port 80 and 443
来端口Nginx reverse proxy
和5000
,因为它们是{{1 }在同一1880
现在,我拥有在.NET Core API
中重新启动这两个AWS EC2 instance
-DEV和PROD的所有命令
以下是我的.NET Core APIs
内容:
rc.local
系统重新启动时,我看到API作为BG进程运行,但我得到rc.local
但是当我使用文件中的相同命令从终端启动相同的API时,即
对于PROD-#!/bin/sh
REM This script will be executed *after* all the other init scripts.
REM You can put your own initialization stuff in here if you don't
REM want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
sudo service Nginx stop
REM DEV -------------------------------------------
REM Removing prevIoUs Error and Output files.
sudo rm /etc/somesite/somesite_dev/Output2.out
sudo rm /etc/somesite/somesite_dev/Error2.err
REM Starting the BG process.
sudo nohup /etc/somesite/somesite_dev/somesite_core_api_dev >
/etc/somesite/somesite_dev/Output2.out 2> /etc/somesite/somesite_dev/Error2.err < /dev/null &
REM Changing Error and Output files permission and Ownership.
sudo chmod 777 /etc/somesite/somesite_dev/Output2.out
sudo chmod 777 /etc/somesite/somesite_dev/Error2.err
sudo chown ec2-user:ec2-user /etc/somesite/somesite_dev/Output2.out
sudo chown ec2-user:ec2-user /etc/somesite/somesite_dev/Error2.err
REM ----------------------------------------------
REM PROD -----------------------------------------
REM Removing prevIoUs Error and Output files.
sudo rm /etc/somesite/somesite_prod/Output3.out
sudo rm /etc/somesite/somesite_prod/Error3.err
REM Starting the BG process.
sudo nohup /etc/somesite/somesite_prod/somesite_core_api_prod >
/etc/somesite/somesite_prod/Output3.out 2>
/etc/somesite/somesite_prod/Error3.err < /dev/null &
REM Changing Error and Output files permission and Ownership.
sudo chmod 777 /etc/somesite/somesite_prod/Output3.out
sudo chmod 777 /etc/somesite/somesite_prod/Error3.err
sudo chown ec2-user:ec2-user /etc/somesite/somesite_prod/Output3.out
sudo chown ec2-user:ec2-user /etc/somesite/somesite_prod/Error3.err
REM ----------------------------------------------
REM Force Stoping and Starting Nginx
sudo service Nginx start
对于DEV-400 Bad request
我得到sudo nohup /etc/somesite/somesite_prod/somesite_core_api_prod > /etc/somesite/somesite_prod/Output3.out 2> /etc/somesite/somesite_prod/Error3.err < /dev/null &
的API正常工作
如果有人可以帮助,我不确定我在这里缺少什么。
谢谢
解决方法
REM是DOS的注释命令。在Linux中,您可以使用#开头注释。在Linux中,REM是未知命令,它将导致脚本中止。您是否已在系统日志中查找错误?
rc.local以root身份运行。这些sudo
都不是必需的。而且rc.local不在终端中运行,因此不需要nohup
行。
不要使文本文件可执行。不要使用chmod 644,而不要使用chmod 777。
无需删除以前的日志文件。您的重定向将覆盖它们。另外,如果文件不存在,您的“ rm”将失败。
不要以这种方式启动nginx。我不知道您使用的是哪个发行版,但是有明确定义的方式来表示“ nginx必须在启动时启动”。这就是您应该用来启动somesite_core_api_dev的方法,但我们可以放手。