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

The method of CentOS6 using nginx to build web website Service

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Using CentOS6 to build a simple web service

Tip: it does not involve the installation and use of MySQl and MongoDB, including docker containers, etc., use nginx reverse proxy static service

CentOS server

You can choose a foreign or domestic server. Only the centOS system configuration is shown here. I do the following under the window system.

Choose and purchase a suitable CVM and the system is centOS

Install xshell and xftp under the window system to ensure that the system can access the centOS system

Connect to the CVM using xshell and log in using Super Admin root

Install nginx after login is complete

Here are the files you need to download:

First install the gcc compilation environment # yum install gcc-c++nginx since wget # yum install wgetnginx. The http module needs to use pcre to parse the regular expression # yum-y install pcre pcre-devel dependent decompression package # yum-y install zlib zlib-devel download the nginx package # wget-c https://nginx.org/download/nginx-1.10.3.tar.gz

Decompression and installation:

Extract nginx # tar-zxvf nginx-1.10.3.tar.gz into the nginx directory # cd nginx-1.10.3 to compile the nginx source code #. / configure start compiling # make continue compiling # make install check the directory installed by nginx # whereis nginx it will tell you where the nginx is, and the nginx command is in the / usr/local/nginx/sbin directory

Nginx command:

Nginx command turns on #. / nginx

Stop #. / nginx-s stop

#. / nginx-s quit

Restart #. / nginx-s reload

Enabling nginx #. / nginx must be enabled in the sbi file under the installation directory of nginx. Of course, it can also be configured globally.

Check whether nginx # ps aux is enabled | grep nginx

Nginx configuration

The following are some references to the nginx configuration

# http serverserver {listen 80; server_name www.didiheng.com; # charset koi8-r; # access_log logs/host.access.log main; access_log off; # cache log off server_tokens off; tcp_nopush on; tcp_nodelay on; gzip on; # gzip enable gzip_comp_level 6; # gzip ratio gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png Proxy_connect_timeout 5; # Cache link proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; location / {root / www; # here absolute address index index.html index.htm; try_files $uri $uri/ / index.html / / configure rewrite ^ (. *) $https://$host$1 permanent; / forced directed https} # error_page 404 / 404.html to use client routing; # redirect server error pages to the static page / 50x.html # error_page 500502 503 504 / 50x.html; location = / 50x.html {root html;} # https server server {listen 443 ssl; server_name www.didiheng.com; ssl_certificate server.crt Ssl_certificate_key server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ssl_prefer_server_ciphers on; access_log off; server_tokens off; tcp_nopush on; tcp_nodelay on; expires epoch; gzip on; gzip_comp_level 6 Gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; location / {root / www; index index.html index.htm Try_files $uri $uri/ / index.html;}

In the above configuration, I directly enabled https. If there is no relevant ssl configuration, please use # to annotate the https service.

Restart nginx after modification

#. / nginx-s reload

Access using serverIP or domain name

Github original address

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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