Home> System Tutorial> LINUX> body text

Build an http server on Linux to realize interaction between client and server

王林
Release: 2024-06-20 06:06:25
Original
1168 people have browsed it

在 Linux 上搭建 http 服务器,实现客户端与服务器的交互

Many services can be built on Linux. The most basic service is to provide a corresponding web socket, allowing the client to obtain network data and realize communication between the client and the server. Especially in the era of China Unicom InternetLinux building web services, the mobile client is mainly used to display corresponding information due to its weak calculation ability, and obtain the information that needs to be interpreted through interaction with the web server. This is also a basic application of the web. It is easy to build an http server on Linux.

nginx server installation

It is more convenient to install software under Linux. Many organizations maintain a set of software sources. Through the installation command, you will know to download the corresponding application from this software source and install it locally. The installation command under ubuntu is apt-getinstall.

Under Linux, there are many http servers. The largest share of the market is apache server. In recent years, nginx server has also become more popular. Here we choose nginx. The installation is as follows:

apt-get install nginx
Copy after login

linux搭建web服务_搭建服务费怎么开发票_搭建服务器的步骤

After completing the installation, start the nginx server:

/etc/init.d/nginx start
Copy after login

After installing nginx, or after installing most software services, you can find the startup command of the corresponding service under /etc/init.d/. Start the nginx service here.

Enter in the browser: 192.168.100.128 is the external IP address of this liunx. If you don’t know your own IP address, you can check it through ifconfig, and it will be displayed in the browser:

linux搭建web服务_搭建服务器的步骤_搭建服务费怎么开发票

indicates that our server has been successfully started.

Most service programs have common configuration files, usually the storage directory is under /etc/, and the nginx configuration directory is under /etc/nginx/:

root@ubuntu:/etc/nginx# ls -lh total 56K drwxr-xr-x 2 root root 4.0K Nov 10 01:27 conf.d -rw-r--r-- 1 root root 1.1K Feb 112017 fastcgi.conf -rw-r--r-- 1 root root 1007 Feb 112017 fastcgi_params -rw-r--r-- 1 root root 2.8K Feb 112017 koi-utf -rw-r--r-- 1 root root 2.2K Feb 112017 koi-win -rw-r--r-- 1 root root 3.9K Feb 112017 mime.types -rw-r--r-- 1 root root 1.5K Feb 112017 nginx.conf -rw-r--r-- 1 root root180 Feb 112017 proxy_params -rw-r--r-- 1 root root636 Feb 112017 scgi_params drwxr-xr-x 2 root root 4.0K Oct 20 01:34 sites-available drwxr-xr-x 2 root root 4.0K Oct 20 01:34 sites-enabled drwxr-xr-x 2 root root 4.0K Oct 20 01:34 snippets -rw-r--r-- 1 root root664 Feb 112017 uwsgi_params -rw-r--r-- 1 root root 3.0K Feb 112017 win-utf
Copy after login

搭建服务器的步骤_搭建服务费怎么开发票_linux搭建web服务

Under the configuration file, you can build the corresponding site on LinuxLinux and configure the web service, and configure the site.

Install PHP

After installing nginx, usually nginx is used as a server, and a scripting language is needed to output html. There are many scripting languages: php, python, etc. Here, php is used. The same technique is used to install php. .

apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-curl php7.0-cli php7.0-mcrypt php7.0-mbstring php7.0-dom
Copy after login

Simply compile a few lines of php test code,


        
Copy after login

Name it index.phplinux software engineer training, save it in the /var/www/ directory, change the site configuration information of /etc/nginx/sites-enabled/default red hat linux, add:

location ~ .php$ { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
Copy after login

linux搭建web服务_搭建服务费怎么开发票_搭建服务器的步骤

Parse the php configuration file and enter

in the browser

Can be displayed on the page

helloworld!!

Summarize

In terms of Linux operation, the main content of this chapter is about web servers. The main purpose here is to be familiar with the installation and configuration of Linux software services. There is a lot of knowledge about web servers, so I won’t introduce them one by one here.

The above is the detailed content of Build an http server on Linux to realize interaction between client and server. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!