AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-494091

Jorge Mauricio's questions

Martin Hope
Jorge Mauricio
Asked: 2025-01-18 07:54:31 +0800 CST

Ubuntu 22.04 - 安装 MySQL 5.7 - 自动化脚本

  • 5

我正在开发一个我们正在自动化部署的旧平台。它需要多次迭代才能达到我们在生产中使用的程度。现在,我正处于设置和配置基本 MySQL 5.7 的步骤中。

环境

  • Ubuntu 22.04
  • AWS

在这个阶段,它是一个我们在本地运行的 Bash 脚本,它会配置远程服务器中的所有内容。稍后,我们将转换为 GitHub 操作,这种策略在过去对我们来说是有效的,所以让我们坚持最初的架构。

这是我在服务器上手动运行且运行良好的工作概念验证:

# Firewall configuration.
sudo ufw allow 3306/tcp;

sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb;

echo "mysql-apt-config mysql-apt-config/select-server select mysql-5.7" | sudo debconf-set-selections;
echo "mysql-apt-config mysql-apt-config/select-product select Ok" | sudo debconf-set-selections;

# Install MySQL APT configuration package
sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.12-1_all.deb;

# Download and add the key directly using the key ID
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C;

# Add the MySQL repository
echo "deb http://repo.mysql.com/apt/ubuntu bionic mysql-5.7" | sudo tee /etc/apt/sources.list.d/mysql.list;

sudo apt-get update;

# Set root password non-interactively
export CONFIG_SERVER_MYSQL_ROOT_PASSWORD='exEm!@123'; # This will be set in the environment variable that I'll show later.
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password '${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}'";
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password '${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}'";

# Install MySQL 5.7
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-community-server=5.7* mysql-client=5.7*;

# Stop MySQL
sudo systemctl stop mysql;

# Created MySQL directory and set permissions
sudo mkdir -p /var/run/mysqld;
sudo chown mysql:mysql /var/run/mysqld;
sudo chmod 777 /var/run/mysqld;

# Start MySQL in safe mode
sudo mysqld_safe --skip-grant-tables --skip-networking &

# Wait for MySQL to start
sleep 5;

# Execute MySQL commands
mysql --user=root << EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}';
FLUSH PRIVILEGES;
EOF

# Stop MySQL in safe mode
sudo pkill mysqld;
sleep 5;

# Start MySQL normally
sudo systemctl start mysql;

# Check if the password worked:
mysql -u root -p'sistemA!@2131' -e "SELECT 1;";

# Check verion:
mysql -u root -p"${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}" -e "SELECT VERSION();";

到目前为止,这是我在自动脚本中转换为本地运行的方式:

# Here is where the .env variables get loaded.
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/single-server-load-env.sh";


BACKEND_HOST_SERVER_SH_SCRIPT='
    # Firewall configuration. \
    sudo ufw allow 3306/tcp; \

    # Update package lists \
    sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb; \

    # Set non-interactive mode. \
    echo "mysql-apt-config mysql-apt-config/select-server select mysql-5.7" | sudo debconf-set-selections; \
    echo "mysql-apt-config mysql-apt-config/select-product select Ok" | sudo debconf-set-selections; \

    # Install MySQL APT configuration package. \
    sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.12-1_all.deb; \

    # Download and add the key directly using the key ID. \
    # Note: The key is deprecated and may not work somewhere in the future, so be sure to always check if it iss up to date. \
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C; \

    # Add the MySQL repository. \
    echo "deb http://repo.mysql.com/apt/ubuntu bionic mysql-5.7" | sudo tee /etc/apt/sources.list.d/mysql.list; \

    # Update package lists. \
    sudo apt-get update; \

    # Set root password non-interactively. \
    sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password '"$CONFIG_SERVER_MYSQL_ROOT_PASSWORD"'"; \
    sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password '"$CONFIG_SERVER_MYSQL_ROOT_PASSWORD"'"; \

    # Install MySQL 5.7. \
    sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-community-server=5.7* mysql-client=5.7*; \

    # Stop MySQL \
    sudo systemctl stop mysql; \

    # Created MySQL directory and set permissions. \
    sudo mkdir -p /var/run/mysqld; \
    sudo chown mysql:mysql /var/run/mysqld; \
    sudo chmod 777 /var/run/mysqld; \

    # Start MySQL in safe mode and wait for MySQL to start. \
    sudo mysqld_safe --skip-grant-tables --skip-networking &
    sleep 5; \

    # This next block is probably where I am having syntax issues:
    # Execute MySQL commands. \
    mysql --user=root << EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}';
FLUSH PRIVILEGES;
EOF
        # Did not work
        # Also tried to escape some single quotes but did not work

    # Execute MySQL commands. \
    mysql --user=root -e "FLUSH PRIVILEGES;"; \
    mysql --user=root -e "UPDATE mysql.user SET authentication_plugin='mysql_native_password', Password=PASSWORD('${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}') WHERE User='root';"; \
    mysql --user=root -e "FLUSH PRIVILEGES;";  \
        # Did not work

    # Execute MySQL commands. \
    mysql --user=root -e "FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${CONFIG_SERVER_MYSQL_ROOT_PASSWORD}'; FLUSH PRIVILEGES;"; \
        # Did not work
    

    # Stop MySQL in safe mode. \
    sudo pkill mysqld; \
    sleep 5; \

    # Start MySQL normally. \
    sudo systemctl start mysql; \

    # This block I am also having problems.
    # Check if the password worked: \
    mysql -u root -p'"$CONFIG_SERVER_MYSQL_ROOT_PASSWORD"' -e "SELECT 1;";

    # This one too.
    # Check verion: \
    mysql -u root -p"'"$CONFIG_SERVER_MYSQL_ROOT_PASSWORD"'" -e "SELECT VERSION();";
';

# Write the private key to a temporary file
echo -e "$CONFIG_SERVER_PUBLIC_KEY" > id_rsa_server_private_key_temp.pem;
chmod 600 id_rsa_server_private_key_temp.pem;

# Execute the script on the server
ssh -v -t -t -i id_rsa_server_private_key_temp.pem \
    -o ConnectTimeout=300 \
    -o StrictHostKeyChecking=no \
    ubuntu@"$CONFIG_SERVER_BACKEND_IP" "$BACKEND_HOST_SERVER_SH_SCRIPT";

# Remove the temporary private key
rm id_rsa_server_private_key_temp.pem;

echo "Status check: Basic MySQL 5.7 installation completed.";

终端日志错误如下所示:

# More informatio, but mostly successful.
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
NEEDRESTART-VER: 3.5
NEEDRESTART-KCUR: 6.5.0-1022-aws
NEEDRESTART-KEXP: 6.5.0-1022-aws
NEEDRESTART-KSTA: 1
2025-01-17T23:50:05.205820Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2025-01-17T23:50:05.233249Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded
                                                      ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded  
                                                                                                            2025-01-17T23:50:11.399290Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to 123.123.123.1 closed.
Transferred: sent 6380, received 26264 bytes, in 39.7 seconds
Bytes per second: sent 160.7, received 661.7
debug1: Exit status 1
Status check: Basic MySQL 5.7 installation completed.

重要提示:

  • 环境变量CONFIG_SERVER_MYSQL_ROOT_PASSWORD应该能够保存复杂的密码,例如:exEm!@123
  • 在 .env 文件中,环境变量定义为 CONFIG_SERVER_MYSQL_ROOT_PASSWORD='exEm!@123' (带单引号)

我已经完成了很多这样的自动化步骤。以下是工作步骤的示例:

# Here is where the .env variables get loaded.
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/single-server-load-env.sh";

# Step: Create directory for the application (host server)
BACKEND_HOST_SERVER_SH_SCRIPT=' \
    # Create application directory \
    sudo mkdir -p /var/www/'"$APP_URL"'; \
    sudo mkdir -p /var/www/'"$APP_URL"'/public; \

    # Set ownership to root \
    sudo chown root:root /var/www/'"$APP_URL"'; \

    # Set directory permissions to 755 \
    sudo chmod 755 /var/www/'"$APP_URL"'; \

    # echo "Application directory created and permissions set.";
';

# Write the private key to a temporary file
echo -e "$CONFIG_SERVER_PUBLIC_KEY" > id_rsa_server_private_key_temp.pem;
chmod 600 id_rsa_server_private_key_temp.pem;

# Execute the SFTP configuration script on the server
ssh -v -t -t -i id_rsa_server_private_key_temp.pem \
    -o ConnectTimeout=300 \
    -o StrictHostKeyChecking=no \
    ubuntu@"$CONFIG_SERVER_BACKEND_IP" "$BACKEND_HOST_SERVER_SH_SCRIPT";

# Remove the temporary private key
rm id_rsa_server_private_key_temp.pem;

echo "Status check: Application directory created and configured successfully!";

(仅展示一个简单的示例来了解合并 .env 变量的语法如何完美工作)

我可以尝试什么想法来修复语法?

linux
  • 1 个回答
  • 36 Views
Martin Hope
Jorge Mauricio
Asked: 2024-01-28 06:17:21 +0800 CST

在 Docker 容器构建/运行命令上设置 GitHub Actions Secret

  • 5

在 Docker 容器构建/运行命令上设置 GitHub Actions Secret

我正处于构建自动化管道的早期阶段。仍处于探索阶段。现在,我正在努力为我要运行应用程序的容器设置环境变量。

这个想法是将我的环境变量设置为 GitHub Actions Secrets,并在运行 docker 容器命令时在容器中配置它们。该容器是根据 Docker Composer 文件构建的。

现在,我有这个工作:

- name: Backend - Build Container (proof of concept)
  run: |
    BACKEND_CONTAINER_SH_SCRIPT='eval "GITHUB_USER=123 GITHUB_REPO_NAME=321 docker-compose -f ss-build-files/ubuntu-container-build.yml up -d && docker-compose -f ss-build-files/ubuntu-container-build.yml logs";'
    echo "${{ secrets.CONFIG_SERVER_SSH_KEY }}" > id_rsa_ssh_key_server_temp.pem;
    chmod 600 id_rsa_ssh_key_server_temp.pem;
    ssh -v -t -t -i id_rsa_ssh_key_server_temp.pem -o StrictHostKeyChecking=no ubuntu@${{ env.CONFIG_SERVER_IP }} "$BACKEND_CONTAINER_SH_SCRIPT"
    rm id_rsa_ssh_key_server_temp.pem;
    echo "Status check: jobs completed successfully!";

但是,当我尝试与 GitHub 机密集成时,它在 GitHub Runner 中返回一个错误:

- name: Backend - Build Container (proof of concept)
  run: |
    BACKEND_CONTAINER_SH_SCRIPT='eval "GITHUB_USER=x${{ secrets.TEST_1 }} GITHUB_REPO_NAME=xx${{ secrets.TEST_2 }} docker-compose -f ss-build-files/ubuntu-container-build.yml up -d && docker-compose -f ss-build-files/ubuntu-container-build.yml logs";'
    echo "${{ secrets.CONFIG_SERVER_SSH_KEY }}" > id_rsa_ssh_key_server_temp.pem;
    chmod 600 id_rsa_ssh_key_server_temp.pem;
    ssh -v -t -t -i id_rsa_ssh_key_server_temp.pem -o StrictHostKeyChecking=no ubuntu@${{ env.CONFIG_SERVER_IP }} "$BACKEND_CONTAINER_SH_SCRIPT"
    rm id_rsa_ssh_key_server_temp.pem;
    echo "Status check: jobs completed successfully!";

错误:

debug1: Sending command: eval "GITHUB_USER=x*** GITHUB_REPO_NAME=xx*** docker-compose -f ss-build-files/ubuntu-container-build.yml up -d && docker-compose -f ss-build-files/ubuntu-container-build.yml logs";
bash: line 1: secret1: command not found
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to 3.90.173.47 closed.
Transferred: sent 2892, received 2676 bytes, in 0.5 seconds
Bytes per second: sent 6131.9, received 5673.9
debug1: Exit status 127
Error: Process completed with exit code 127.

注意:我以这种方式构建,因为eval "GITHUB_USER=123 GITHUB_REPO_NAME=321 docker-compose -f ss-build-files/ubuntu-container-build.yml up -d && docker-compose -f ss-build-files/ubuntu-container-build.yml logs"考虑到我希望完成的任务,这似乎是它的唯一工作方式,即创建一个节点脚本,该脚本从存储库读取所有 Secret(应用程序有许多环境变量)并输出像这样的字符串:

TEST_1=${{ secrets.TEST_1 }} TEST_2=${{ secrets.TEST_2 }}

我将把这个字符串与 Docker 容器命令的其余部分合并。

任何人都知道它给我这个错误的原因,或者可能有另一个想法如何在不硬编码服务器/容器中的 .env 文件的情况下自动化这部分?

ubuntu
  • 1 个回答
  • 27 Views
Martin Hope
Jorge Mauricio
Asked: 2022-02-28 14:28:23 +0800 CST

用于 docker 镜像验证的 Puppet manifest 配置

  • 1

我对 devops/ci/cd 很陌生,所以请耐心等待。

目前,我正在为 docker 图像验证设置一个 puppet manifest 配置。让我尝试布局它:

我有一个具有以下配置的 puppet master 服务器:

  • Puppetmaster 版本:5.5.10-4ubuntu3
  • 两台服务器都是linux 20.04
  • 全部托管在 AWS 上

/etc/puppet/code/environments/production/manifests/site.pp

node default {
    include 'docker'
    docker::image { 'jorgemauriciodev/ubuntu-dockerfile-dev-v1': }
}

每次在 .pp 中尝试新的验证命令时,我都会使用以下命令重新启动 puppet master 服务器:sudo systemctl restart puppet-master

我在我的两台服务器(代理和主服务器)上都安装了一个名为 garethr-docker 的模块。

在从/代理服务器上,我有这个镜像 docker 镜像存在并正在运行:jorgemauriciodev/ubuntu-dockerfile-dev-v1 第一步,我只想检查我的从属服务器中是否存在该镜像。稍后,我将确定它正在运行或使用 Dockerfile 构建。

在从/代理服务器上,我运行:sudo puppet agent –test

我收到以下错误消息:

错误:无法从远程服务器检索目录:服务器上的错误 500:服务器错误:评估错误:评估函数调用时出错,找不到类 ::docker 用于 ip-123-123-123-123.us-east- 2.compute.internal(文件:/etc/puppet/code/environments/production/manifests/site.pp,行:2,列:5)在节点 ip-123-123-123-123.us-east-2 .compute.internal 警告:未在失败的目录上使用缓存错误:无法检索目录;跳过跑步

有人知道我对 puppet 清单文件有什么问题吗?

编辑1:

我做了一些建议的更改。现在,我的文件有一个不同的名称并更改了内容:/etc/puppet/code/environments/production/manifests/init.pp

include 'docker'
class { 'docker':
  version => 'latest',
}
docker::image { 'jorgemauriciodev/ubuntu-dockerfile-dev-v1': }

仍然返回相同的错误消息。

这是完整的消息:

/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/indirector/request.rb:272: warning: URI.unescape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Info: Retrieving plugin
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/indirector/request.rb:272: warning: URI.unescape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Info: Retrieving locales
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/indirector/request.rb:272: warning: URI.unescape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::docker for ip-172-31-21-116.us-east-2.compute.internal (file: /etc/puppet/code/environments/production/manifests/init.pp, line: 1, column: 1) on node ip-172-31-21-116.us-east-2.compute.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
/usr/lib/ruby/vendor_ruby/puppet/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0

编辑2:

我使用以下命令在主服务器和从/代理服务器上安装了更多模块:

sudo puppet module install puppetlabs-docker --version 4.1.2

它仍然向我返回一条错误消息,但现在似乎它是一个不同的消息。所以,现在可能是一个语法问题。

这是消息的重要部分。

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Docker] is already declared; cannot redeclare (file: /etc/puppet/code/environments/production/manifests/init.pp, line: 3) (file: /etc/puppet/code/environments/production/manifests/init.pp, line: 3, column: 1) on node ip-123-123-123-123.us-east-2.compute.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

除了这条消息,它仍然向我返回那些警告,但列表要大得多。但是,我认为目前这不是问题。

ubuntu puppet devops puppetmaster puppet-agent
  • 1 个回答
  • 103 Views
Martin Hope
Jorge Mauricio
Asked: 2021-10-25 08:06:15 +0800 CST

如何在 windows server 2016 / IIS 上部署服务器端渲染 (SSR) 反应应用程序(由 webpack 捆绑)

  • 0

提个醒:这是我第一次尝试在定制的 Windows 服务器上部署 react 应用程序,但我已经成功地在 Heroku 和 Linux (PM2) 上完成了它,所以我知道应用程序架构是假设的正常工作。

场景:

我已经构建了一个 Windows Server 2016 / 64 位托管服务器来托管多个网站。我已经使用 VPS Contabo 来做到这一点。我已经测试了所有应该工作的功能,即使是其他应用程序,如 ASP.NET、PHP、SSL 证书,一切都运行良好。

至于我试图在此服务器上托管的特定节点 js 项目,它由 2 个主要部分组成:

  • node 中的后端与 CMS 一起使用 node / javascript 开发。

我为此在子域上创建了一个托管空间,它运行良好,即使使用 Let's Encrypt SSL 证书也是如此。如果有人想访问它,请访问: https ://backendnode.fullstackwebdesigner.com/system

  • 反应服务器端渲染中的前端。

这就是问题发生的地方。如果有人想访问它,这里是链接: https ://fullstackwebdesigner.com/

我对它们都使用了基本相同的技术:

  • iis节点;
  • URL重写扩展;
  • iis节点模块;
  • web.config 文件配置;

问题:

我已经设法让它作为一个网站加载,就像我对后端所做的那样,但问题是它似乎没有加载 CSS 文件、图像等。所以布局不会加载。在控制台上,有错误消息: Uncaught SyntaxError: Unexpected token '<'

react 应用程序:正如我之前所说,它是作为服务器端渲染应用程序完成的,并与 webpack 捆绑在一起。因此,它将捆绑的文件构建到名为“/build”的目录中。在这个目录中,有一个“/public”目录,所有资产都在其中,例如 CSS 文件和图像。

在开发时,我会在终端上运行构建:node build/bundle.react.js

尽管看起来很奇怪,但当我在 Windows 服务器的终端上运行它时,它运行良好。但只能通过以下方式访问:http://localhost:3001 它会加载所有应该加载的内容。

这是文件结构的简化表示:

- /build/
--bundle.react.js
--/build/public/
---/files-layout/
---/fonts/
---bundle.react.client.js

这也是我在网站托管空间上用于反应构建的 web.config 文件:

<configuration>
    <system.webServer>
        <iisnode nodeProcessCommandLine="C:\Program Files\nodejs\node.exe" />
        
        <handlers>
            <add name="iisnode" path="/build/bundle.react.js" verb="*" modules="iisnode" />
        </handlers>

        <rewrite>
            <rules>
                <!-- Redirect to HTTPS (alternative). -->
                <rule name="Redirect to HTTPS / SSL" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
                </rule>

                <!-- Don't interfere with requests for logs. -->
                <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$" />
                </rule> 
                <!-- Node. -->
                <rule name="sendToNode">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/build/bundle.react.js" />          
                </rule>
            </rules>    
        </rewrite> 
        <defaultDocument>
            <files>
                <clear />
                <add value="/build/bundle.react.js" />
            </files>
        </defaultDocument>
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <add segment="node_modules" />
                </hiddenSegments>
            </requestFiltering>
        </security>
    </system.webServer>
    <system.web>
        <compilation defaultLanguage="js" />
    </system.web>
</configuration>

任何人都知道可能缺少什么或正在发生什么,因为在 web 上的 windows 服务器上托管服务器端渲染的参考文献不多?可能是 IIS、web.config 或网站托管空间上的额外配置?

编辑:

我刚刚做了一个有趣的测试:在我的本地开发计算机上,当我通过终端运行时:

node bundle.react.js

从 /build 文件夹中,我得到与在线发生的问题相同的结果(没有布局、样式、图像等)。

但是当我通过终端运行时:

node build/bundle.react.js

从 /build 文件夹外部(从基本目录),它可以完美加载。

关于更多的事情。基本目录的组织方式如下:

…(some folders)
- /build/
--bundle.react.js
--/build/public/
---/files-layout/
---/fonts/
---bundle.react.client.js
-node_modules
…(some root files, like webpack and so on)

我猜由于我如何编写 web.config 文件,引用 /node_modules 文件夹存在某种问题,但我不知道应该如何引用它。

deployment iis node.js windows-server-2016
  • 1 个回答
  • 923 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve