In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to build a static website in NGINX". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to build a static website in NGINX.
Build Http static server environment
Task time: 15min ~ 30min
To build a static website, you first need to deploy the environment. The following steps will show you how to deploy the HTTP static service on the server through Nginx.
00. Install Nginx
On CentOS, you can use yum directly to install Nginx
Yum install nginx-y
After the installation is complete, use the nginx command to start Nginx:
Nginx
At this point, visit http://ip to see the test page of Nginx [?]
If you cannot access it, retry the nginx-s reload command to restart Nginx
01. Configure static server access path
The Web service for external network users to access the server is provided by Nginx. Nginx needs to configure the path information of static resources in order to correctly access static resources on the server through url.
Open the default configuration file / etc/nginx/nginx.conf of Nginx, modify the Nginx configuration, and change the default root / usr/share/nginx/html; to: root / data/www;, as follows:
Sample code: / etc/nginx/nginx.confuser 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 500502503504 / 50x.hml; location = / 50x.html {}}
The configuration file uses / data/www/static as the root path for all static resource requests, such as visiting: http:///static/index.js, which will go to the / data/www/static/ directory to look for index.js. Now we need to restart Nginx for the new configuration to take effect, such as:
Nginx-s reload
After restarting, we should now be able to use our static server. Now let's create a new static file to see if the service is running properly.
First, let's create a www directory under the / data directory, such as:
Mkdir-p / data/www02, create the first static file
Create our first static file index.html in the / data/www directory
Sample code: / data/www/index.html the first static file Hello world!
If it is not displayed, refresh the browser page
Thank you for your reading, the above is the content of "how to build a static website in NGINX". After the study of this article, I believe you have a deeper understanding of how to build a static website in NGINX, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.