部署shopifyapp服务

343 阅读2分钟

此文章是使用自己的服务器来部署服务,并进行安装的方法

官方文档部署的推荐服务商是Fiy.io和Heroku,如果选择这些服务商可以按照文档来进行

必要准备

  1. 服务器 本文以Ubuntu来进行按照,有个点,需要注意服务器可以按照node18以上的版本
  2. 域名
  3. 代码

开始安装

1.安装node

     sudo apt-get update
     curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
     sudo apt-get install -y nodejs

查看安装是否成功

 node -v
 npm -v

2.安装pm2 npm install -g pm2

3.将插件代码上传到服务器,安装依赖进行打包

npm i
npm run build

4.配置项目环境变量 vim ~/.bashrc 将需要的环境变量编辑到这个里面 source ~/.bashrc 生效这些配置 5.运行项目 pm2 start npm --name "项目名" -- start 此时项目已经成功运行,可以通过ip+端口 默认端口是3000

配置nginx、https

1.安装nginx sudo apt install nginx 2.配置证书即https,可以通过这个免费的证书来部署 certbot.eff.org/instruction… 傻瓜式的安装方式,只需要选择web服务的部署方式和系统

3.修改nginx的配置 通过nginx -t来找到安装的nginx的配置信息,修改配置

server {

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        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 shopify.ui.ashimarywig.com; # managed by Certbot

        ## 修改的地方 start
        location / {
        proxy_pass http://127.0.0.1:3000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
        #       try_files $uri $uri/ =404;
        }
        ## 修改的地方 end
        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/shopify.ui.ashimarywig.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/shopify.ui.ashimarywig.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

然后重启nginx

nginx -s reload

以上 如果你已经完成了域名的解析,可以直接通过域名进行访问了

shopify开发者完成配置

登录shopify开发者后台 找到你在上面部署的应用 ,在此应用里面配置选项的url的应用url输入你的域名

image.png

选择分发模式,进行分发就可以了

到这里就完成了shopify插件的开发部署