行者lwl
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 简单前后端分离项目部署 ## 简介 我是部署我的简单动漫网站的时候碰到这方面的问题。 我的项目技术栈: - 使用python flask 作为后端 - 使用vue编写前端 ## 文件传输到服务器上 方法有很多,我直接将项目上传到github, 然后pull到云端。 ![](https://i.imgur.com/vSb8z4e.png) ## 将后端跑起来 我这里直接使用python命令行启动 ``` python /root/lwl/code/python/deploy/flaskApi.py & # 运行指定项目 ``` 虽然后端运行了起来,但是这时候我们还不能通过公网ip去进行访问。 要将防火墙打开。 ``` firewall-cmd --zone=public --add-port=5000/tcp & #开启防火墙端口 ``` 同时腾讯这也要进行防火墙管理 ![](https://i.imgur.com/qUf2QCz.png) ![](https://i.imgur.com/akNp6FA.png) 然后就可以访问到了 ![](https://i.imgur.com/zau9TTN.png) ## 前端部署 我这里的前端, 属于传统前端,主要有html,css,js等静态文件组成。 我使用VUE,所以使用npm run build 进行打包 ![](https://i.imgur.com/Ls4rPfU.png) 这时候,我们的前端就已经打包完毕了。 重点来了 **使用某个服务器对静态资源进行代理** 我使用的是nginx。 以下是我的配置 ``` user root; # 用户 worker_processes auto; error_log /www/wwwlogs/nginx_error.log crit; pid /www/server/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include mime.types; #include luawaf.conf; include proxy.conf; default_type application/octet-stream; server_names_hash_bucket_size 512; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn_zone $server_name zone=perserver:10m; server_tokens off; # 访问日志配置在这 #自定义名为main得日志格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /www/wwwlogs/access.log main; # 这里是具体路径 # 这里是我们需要注意的东西,也是配置主要需要修改的东西 server { #我们访问119.29.143.49:88 listen 80; # 端口 server_name 119.29.143.49; # 服务器名, 要代理的服务器的名字 #存放静态资源的文件路径 root /root/lwl/code/python/deploy/front/dist; #ngix的配置文件 include /www/nginx/conf/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } include /www/server/panel/vhost/nginx/*.conf; } ``` 我这里只对简单的静态资源代理进行举例,关于后端的代理可以自行浏览nginx的用例 ### Nginx下vue等打包静态资源的路由问题 因为vue打包后是单个html,url也是vue内部的。所以刷新页面会出现下面问题。 ![](https://i.imgur.com/OMG5QAv.png) 参考资料[链接](https://learnku.com/articles/34440) 解决问题 在服务端nginx配置里添加vue-route的跳转设置(这里首页是index.html,如果是index.php就在下面对应位置替换),正确配置如下: ``` server { listen 80; server_name testwx.wangshibo.com; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/ssoShuang/dist; #vue-router配置 location / { try_files $uri $uri/ @router; index index.html; } location @router { rewrite ^.*$ /index.html last; } } ``` 重启 nginx 后,问题就迎刃而解了。 ## 最后讲解自动启动问题 使用ssh 连接后,终端退出那么任务也就没了 所以我使用自动启动 这里主要用systemctl 我的服务器使用centos7,他的systemctl自动启动项在目录 ` /usr/lib/systemd/system/ ` 新建service文件: 我新建了lwl.service文件 ![](https://i.imgur.com/KpvrDEN.png) 具体配置 ``` [Unit] Description=lwl #描述 After=network.target #前置启动的程序 [Service] #具体的命令了 Type=forking ExecStart=/root/init.sh # 开启该任务的命令 ExecReload=/root/init.sh #重启 ExecStop=/root/init.sh #关闭 [Install] WantedBy=multi-user.target ``` **注意** **systemctl执行脚本时需要知道脚本的解释器** 解决方法: 在/root/init.sh脚本的开头加上`#!/bin/sh` 最后的init.sh ``` #!/bin/sh firewall-cmd --zone=public --add-port=5000/tcp & #开启防火墙端口 python /root/lwl/code/python/deploy/flaskApi.py & # 运行指定项目 #用来查找某个端口的进程pid #netstat -nlp | grep 5000 | awk '{print $7}' | awk -F"/" '{ print $1 }' ``` 然后就是一些命令了 ``` #查看日志 $ sudo journalctl -f -u nginx.service — Logs begin at 四 2015-06-25 17:32:20 CST. — 6月 25 10:28:24 Leco.lan systemd[1]: Starting nginx – high performance web server… 启动一个服务:systemctl start nginx.service 关闭一个服务:systemctl stop postfix.service 重启一个服务:systemctl restart nginx.service 显示一个服务的状态:systemctl status postfix.service 在开机时启用一个服务:systemctl enable nginx.service 在开机时禁用一个服务:systemctl disable nginx.service 查看服务是否开机启动:systemctl is-enabled nginx.service 查看已启动的服务列表:systemctl list-unit-files|grep enabled 刚刚配置的服务需要让systemctl能识别,就必须刷新配置 $ systemctl daemon-reload ``` **尽量将运行命令写的精确** 比如我的python有多个版本,那么尽量写成 `/usr/bin/python /root/lwl/code/python/deploy/flaskApi.py & # 运行指定项目` ### 简单讲程序放入后台 nohup命令: 如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。nohup就是不挂起的意思。 我们现在开始启动服务 python pyserver.py,并且希望在后台运行.我们就可以使用nohup,命令如下: `nohup python pyserver.py `

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully