Build Web common software and optimization on CentOS 7

Source: Internet
Author: User
Tags varnish nginx reverse proxy

Web Building and optimization
This article is mainly for Web services, production environment will use some software, just a simple statement, if there is any wrong place, please advise, thank you!

Web-built Software: Httpd,nginx,tomcat
Agent Software: Squid,varnish
Database software: Mariadb,redis,mencache
Verify browsing: elinks-dump, Curl,firefox, etc.
View Web Network listener: NETSTAT/SS-ANPTU | grep httpd/80 Note: We recommend the use of SS, fast
URL (Uniform Resource Locator) consisting of:/HTTP Server address ": Port number"/directory/File name
Detection Web tool: AB Format: ab-c number of concurrent-N requests http://ip/Note: installation is required Httpd-tools
LNMP Note: LAMP a:apache
L:linux
N:nginx
M:MARIADB, Mariadb-server, Mariadb-devel
p:php, PHP-FPM, Php-mysql

===========================================================================

    1. HTTP
      Package: httpd (Apache www.apache.org)
      Installation method: Yum
      Service: httpd
      Transport protocol and port: TCP 80 Note: HTTPS TCP 443 package: Mod_ssl
      Configuration file:
      Master profile:/etc/httpd/conf/httpd.conf Note: generally not modified
      Others:/etc/httpd/conf.d/*.conf
      Default home: index.html
      Default root directory:/var/www/html
      Start service: Systemctl restart httpd systemctl enable httpd

Configuration file Contents:
Listen Port number Note: Add a new Web port semanage port-a-T http_port_t-p TCP port number
<virtualhost *: Port number > Note: Can be based on the ports of the virtual host, as well as IP-based virtual host
ServerName Web site FQDN Note: Can be based on the domain name of the virtual host, using the most
DocumentRoot Web site root directory
Wsgiscriptalias//Website Web page Note: Requires MOD_WSGI module package
</VirtualHost>

<directory "directory path" >
Require all denied??????????????????????????????? ?//Upper directory denies any access
Require all granted//directory allows any access
Require IP IP or network segment address: .. Directory allows a small number of clients
</Directory>

==================================================================================

    1. NGINX (Engine x)
      Package: Nginx (http://nginx.org) Note: Dependent package Pcre-devel Openssl-devel
      Installation method: Source installation Note: Dependent package gcc
      Transport protocol and Port: TCP 80 Note: When you open nginx, you need to close httpd--killall httpd
      Configuration file:/usr/local/nginx/conf/nginx.conf
      Default home: index.html
      Default root directory:/usr/local/nginx/html/
      Start the service:
      /usr/local/nginx/sbin/nginx//Start service
      /usr/local/nginx/sbin/nginx-s Stop//Shutdown service
      /usr/local/nginx/sbin/nginx-s Reload//reload config file equivalent to reboot

Configuration file Contents:
server{
Listen 80; Port
server name localhost; Domain name
Location/{
root HTML; Specify site root directory
Index index.html index.htm; Default Home
rewrite/a.html/b.html; Access a.html Redirect to B.html
}
}

Nginx Reverse proxy (very important):
HTTP {
Upstream webserver {//configure Upstream server cluster pool properties
Server 192.168.2.100 weight=1 max_fails=2 fail_timeout=10; Weight 1, number of failures 1, timeout 10
Server 192.168.2.200 weight=1 max_fails=2 fail_timeout=10;
}
server {
Listen 80;
server_name www.aa.com;
Location/{
Proxy_pass Http://webserver; Implementing Reverse proxy functionality
}
}
}

Nginx Optimization:

Worker-processes 1; Consistent CPU cores view CPU with LSCPU
Events {
Worker_connection 65535; Maximum number of concurrent connections per worker
}
HTTP {
Server_tokens off; Do not display Nginx version number information
Client_header_buffer_size 1k; Cache of Default request header information
Large_client_header_buffers 4 4k; Cache number and capacity of Large request packet header information
gzip on;
Gzip_min_length 1000;
Gzip_comp_level 4;
Gzip_types Text/plain
}

Server {........... Omitted

Location ~*. (Jpg|jpeg|gif|png|css|js|ico|xml) $ (
Expires 30d; Define client cache time of 30 days
)
To modify the maximum number of open files on a Linux operating system
#vim/etc/security/limits.conf (Permanent configuration)

    • Soft Nofile 100000
    • Hard Nofile 100000
      Required settings on Linux systems (temporary settings)
      Ulimit–hn 100000
      ULIMIT–SN 100000

====================================================================
3.TOMCAT
Package: apache-tomcat-8.0.30.tar.gz Note: Dependent package JDK JAVA-1.8.0-OPENJDK
Installation mode: After decompression and copy to/usr/local/tomcat/, you can use
Transport protocol and port: TCP 8080 HTTPS 8443
Configuration file:/usr/local/tomcat/conf/server.xml
Page Catalog:/usr/local/tomcat/webapps/root/
Default home: index.html
Start the service:
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh

Configuration file Contents:
<context path= "" docbase= "base"/>
</Host>

====================================================================

    1. SQUID
      Package: Squid
      Installation method: Yum
      Transport protocols and ports: TCP 80
      Configuration file:/etc/squid/squid.conf
      Start the service:
      Systemctl start Squid;systemctl Enable squid
      Configuration file Contents:
      Http_port vhost//Set up reverse proxy
      Visible_hostname svr5.tarena.com//Set host name, default does not have this statement
      Cache_peer 192.168.2.100 Parent 0 originserver//define back-end real server information
      Cache_dir UFS/VAR/SPOOL/SQUID 200 16 256//hard disk cache, cache capacity 200M, automatically create 16 first level subdirectories and 256 levels of two subdirectories
      Http_access allow all//allows native all hosts to use a proxy server

==========================================================

    1. VARNISH
      Package: varnish-3.0.6.tar.gz Note: Dependent package Read-devel Pcre-devel
      Installation method: Source Installation
      Transport protocols and ports: TCP 80
      Configuration file:
      /etc/sysconfig/varnish
      /etc/varnish/default.vcl
      Start Services: Service varnish start
      Configuration file Contents:
      Vim/etc/sysconfig/varnish
      66 Line: VARNISH_LISTEN_PORT=80//Default port
      89 rows: varnish_storage_size=64m//define Cache size
      92 Rows: varnish_storage= "malloc,${varnish_storage_size}"//memory-based caching

Linux System Processing Process:
Mkdir/etc/varnish
cp/usr/local/varnish/etc/default.vcl/etc/varnish/
Uuidgen >/etc/varnish/secret
Vim/etc/varnish/default.vcl
Configuration content
Backend Default {
. Host = "192.168.2.100";
. Port = "80";
}

==========================================================

Build Web common software and optimization on CentOS 7

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.