This is the fourth day of my participation in Gwen Challenge
Set up the Http static server environment
Build a static website, the first need to deploy the ring
The land. The following steps will show you how to deploy HTTP static services on a server using Nginx.
Install Nginx
On CentOS, you can install Nginx directly with yum
yum install nginx -y
Copy the code
After the installation is complete, start nginx using the nginx command:
nginx
At this point, visit XXX.XXX.xxx. XXX (your domain name) to see the Nginx test page
Configure the static server access path
The Web service for extranet users to access the server is provided by Nginx. Nginx needs to configure the path information of static resources to correctly access static resources on the server through urls.
/usr/share/ Nginx/Nginx/Nginx/Nginx/Nginx/Nginx/Nginx/Nginx/Nginx/Nginx/Nginx Change to root /data/ WWW;
The configuration file is as follows: nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /data/www;
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Copy the code
Configuration file/data/WWW/static as root of all static resource request, such as access: XXX, XXX, XXX, XXX/static/inde… /data/ WWW /static/ Now we need to restart Nginx for the new configuration to take effect:
nginx -s reload
Copy the code
After the restart, we should now be able to use our static server. Let’s now create a new static file to see if the service is working properly.
First let’s create a WWW directory under /data as follows:
mkdir -p /data/www
Copy the code
Create your first static file
Create our first static file index. HTML under /data/ WWW
index.html
Now, visit XXX XXX. XXX. XXX/index. The HTML page you should see the output Hello world!
At this point, a static server based on Nginx is set up, and now all static resources in the /data/ WWW directory can be directly accessed by domain name.
To complete the
A: congratulations! You have successfully completed the experimental task of setting up an Http static server environment.