Building an HTTP static server environment

Source: Internet
Author: User

To build a static website, you need to deploy the environment first. The following steps will tell you how to deploy HTTP static services on the server via Nginx.

Installing Nginx

Yum Install Nginx-y

Start: Nginx

OK after access to access http://119.29.232.198 can see the Nginx test page

Nginx Command Detailed: http://blog.csdn.net/aidenliu/article/details/6413342

To configure a static server access path

Open Nginx's default profile/etc/nginx/nginx.conf, modify the Nginx configuration and change the default root /usr/share/nginx/html; to: root /data/www; , as follows:

Code Demonstration:/etc/nginx/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 _by    Tes_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 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 502 503 504/50x.html; Location =/50x.html {}}}

The configuration file will be /data/www/static as the root path of all static resource requests, such as access: http://<您的域名>/static/index.js , will go to the /data/www/static/ directory to look down index.js . Now we need to restart Nginx for the new configuration to take effect, such as:

Nginx-s Reload

Mkdir-p/data/www //Create www Directory

Create first static file

Create our first static file under the/data/www directory index.html

Code Demonstration:/data/www/index.html

<! DOCTYPE html>"en">" UTF-8 ">    <title> First static file </title>Hello world! </body>

Now access http://119.29.232.198/index.html should be able to see the page output

Hello world!

To this, an Nginx-based static server is built, and now all the static resources placed in the/DATA/WWW directory can be accessed directly through the domain name.

The main purpose of this test is to do nginx load distribution of access monitoring. Hope the great God of crossing don't spray. Welcome to blame questions and suggestions!!!

Building an HTTP static server environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.