Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of the method example of deploying H5 games to nginx server

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the deployment of H5 games to the nginx server example analysis, the content is clear, interested partners can learn, I believe that after reading it will be helpful.

On the way to self-study game development, the most fulfilling moment is to make your Mini Game and share it with your friends to try it out. The original game can be packaged and shared, and the Mini Game launch process is long, so how to share H5 Mini Game? This article will take you through nginx to build a good H5 game hosting on Aliyun.

Content outline:

Download and configure nginx to upload game build files to CVM nginx to set up multiple virtual hosts through ports

Development environment:

Ali CVM: Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-93-generic x86Secret64)

Nginx:nginx/1.4.6 (Ubuntu)

WinSCP:5.15.3

Detailed explanation of the steps:

1. Download and configure nginx

Before we start, let's briefly talk about what nginx,nginx is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server, and released under a BSD-like protocol, which is characterized by low memory and strong concurrency.

The reverse proxy is to accept the connection request on the internet with the proxy server, then forward the request to the server on the internal network, and return the result obtained from the server to the client requesting the connection on the internet. At this time, the proxy server appears as a server.

In fact, load balancing is to distribute traffic to multiple servers to reduce the pressure on each server, and multiple servers work together to complete tasks, thus improving data throughput, thus expanding the bandwidth of network devices and servers, increasing throughput, strengthening network data processing capacity, and improving network flexibility and availability.

Using nginx, we can separate static and static resources and put static resources in nginx, while dynamic resources run in TomCat servers. When accessing static resources, we can directly request nginx, and there is less pressure on the server to request TomCat.

At present, two installation methods are supported, one is based on APT source installation, the other is compiled and installed through the source package, but if you want to install the latest version, you must download the source package compilation installation. This article is based on the APT source installation, want to know another way of installation can be their own Baidu.

1.1 Update Software Source

Sudo apt-get update

1.2 install nginx

Sudo apt-get install nginx

Note: the location of the installed files:

/ usr/sbin/nginx: main program

/ etc/nginx: store configuration files

/ usr/share/nginx: store static files

/ var/log/nginx: store logs

1.3 check whether nginx is installed successfully

Nginx-v

1.4 start nginx

Service nginx start

1.5 after startup, enter the public network IP of the server in the browser to see the welcome page of nginx, and nginx has been installed successfully.

two。 Upload the game build file to the CVM

2.1 you need to use a tool to upload files to the CVM: WinSCP. I have uploaded the software to Baidu Cloud. The official account can reply "WinSCP" at the backend to get it, and it can be installed without brain operation.

2.2 before uploading files, you need to create a folder in the CVM to place the game build files for a while. Because the build files for two games will be placed later, I have created two more subfolders as follows (I created them under the root directory, and you can create them according to the actual situation. ):

/ www/80

/ www/81

2.3.After creating a folder, you can use WinSCP to upload game build files. Prepare two built games, select all the build files and right-click to upload them to the directory created above:

3.nginx sets up multiple virtual hosts through ports

Also give a brief description of the configuration file of nginx before you begin:

... # global block events {# events block...} http # http block {... # http global block server # server block {... # server global block location [PATTERN] # location block {...} location [PATTERN] {...} server {..}... # http global block}

Global blocks: configure directives that affect the global nginx. Generally, there are user groups running nginx server, pid storage path of nginx process, log storage path, introduction of configuration files, number of worker process allowed to be generated, and so on.

Events block: the configuration affects the nginx server or the network connection to the user. There is a maximum number of connections per process, which event-driven model is selected to handle connection requests, whether multiple network connections are allowed to be accepted at the same time, serialization of multiple network connections is enabled, and so on.

Http blocks: you can nest multiple server, configure proxies, caches, log definitions, and most other functions and configure third-party modules. Such as file introduction, mime-type definition, log customization, whether to use sendfile to transfer files, connection timeout, the number of requests for a single connection, etc.

Server block: configure the relevant parameters of the virtual host. There can be multiple server in a http.

Location blocks: configure the routing of requests and the handling of various pages.

Let's give you a configuration file as an understanding:

# each instruction must end with a semicolon. # user administrator administrators; # configure users or groups. Default is nobody nobody. # worker_processes 2; # the number of processes allowed to be generated. The default is 1#pid / nginx/pid/nginx.pid; # to specify the address where the nginx process runs files to store, error_log log/error.log debug; # to determine the log path and level. This setting can be put into the global block, http block, server block, and the level is: debug | info | notice | warn | error | crit | alert | emergevents {accept_mutex on; # sets the serialization of network connections to prevent the occurrence of panic phenomena. The default is on multi_accept on; # to set whether a process accepts multiple network connections at the same time. The default is off # use epoll; # event-driven model, select | poll | kqueue | epoll | resig | / dev/poll | eventport worker_connections 1024. # maximum number of connections, default is 512} http {include mime.types; # File extension and File Type Mapping Table default_type application/octet-stream; # default file type, default is text/plain # access_log off; # unservice log log_format myFormat'$remote_addr-$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for' # Custom format access_log log/access.log myFormat; # combined is the default value of log format sendfile on; # allows sendfile to transfer files, default is off, can be in http block, server block, location block. Sendfile_max_chunk 100k; # the number of transfers per call per process cannot be greater than the set value. The default is 0, that is, there is no upper limit. Keepalive_timeout 65; # connection timeout. The default is 75s, which can be found in the http,server,location block. Upstream mysvr {server 127.0.0.1server 7878; server 192.168.10.121 backup; # Hot standby} error_page 404 https://www.baidu.com; # error page server {keepalive_requests 120; # maximum number of single connection requests. Listen 4545; # listening port server_name 127.0.0.1; # listening address location ~ * ^. + ${# request url filtering, regular matching, ~ is case-sensitive, ~ * is case-insensitive. # root path; # Root directory # index vv.txt; # set default page proxy_pass http://mysvr; # request to mysvr defined server list deny 127.0.0.1; # rejected ip allow 172.18.5.54; # allowed ip}

By using the virtual host technology, a real host can be divided into many "virtual" hosts, each of which has an independent domain name and IP address and a complete Internet server (www, FTP,email) function. Virtual hosts are completely independent, and in the outside world, each virtual host is exactly the same as an independent host.

Virtual hosts are divided into three types: IP-based virtual hosts, port-based virtual hosts and name-based virtual hosts. This paper uses port-based virtual hosts to set up multiple virtual hosts. Partners who want to know the other two settings can do it on their own.

3.1 Port 80 and 81 are liberalized in this document. Port 80 is the default port. Before you start, you should first open port 81 on Ali CVM:

3.2 after the Ali CVM is configured, you can log in to the server remotely to see if the port has been opened successfully. If the port is not detected, you need to open it manually:

View status:

Iptables-L-n

If you do not have port 81, you need to open port 81:

Open the port:

Iptables-I INPUT-p tcp-- dport 81-j ACCEPT

Close the port:

Iptables-D INPUT-p tcp-- dport 81-j ACCEPT

3.3.After opening the port, you need to configure the nginx.conf file. The above has given a brief introduction to the nginx.conf configuration file. To set multiple virtual hosts through the port, you only need to add a server to listen to the newly opened port:

Server {listen 80; / / listen for port 80 server_name test80.superyu.com; root / www/80; / / project directory location / {index index.html index.htm;} error_page 500502 503 504 / 50x.hml; location = / 50x.html {root html;}} server {listen 81; / / listen for port 81 server_name test81.superyu.cn Root / www/81; / / Project directory location / {index index.html index.htm;} error_page 500502 503 504 / 50x.htl; location = / 50x.html {root html;}}

3.4.After configuring the nginx.conf file, restart nginx to view the effect:

Enter the following command to update the configuration file without closing nginx:

Nginx-s reload

3.5 enter http:// public network: Port in the editor to see the effect as follows:

After reading the above content, do you have a further understanding of the method instance parsing of deploying H5 games to nginx servers? if you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report