In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Nginx website serves as a virtual host
Advantages of 1:nginx:
High stability
Low system resource consumption
Http concurrency has good processing capacity and can support 30000-50000 concurrent requests
Mainly used for static pages
In threads, a process corresponds to multiple users (threads rarely take up system resources)
2: comparison with Apache:
Apache is mainly used for dynamic pages
Many features are supported
High stability
Apache is in units of process, with one user corresponding to one process (one to one)
3:nginx is mainly used for: e-commerce, websites, social networking, portals.
4: install and control nginx
1. Install support softwar
[root@centos1 ~] # yum-y install pcre-devel zlib-devel
two。 Create and run users, groups
[root@centos1] # useradd-M-s / sbin/nologin nginx
3. Compile and install nginx
Enable the status statistics module to support status statistics, making it easy to view the connection information of the server
[root@centos1 nginx-1.6.2] # / configure-- prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-http_stub_status_module (state statistics module)
[root@centos1 nginx-1.6.2] # make&&make install
4. Add symbolic links so that the main program of nginx can be called through the nginx command
[root@centos1 nginx-1.6.2] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin
two。 Start and stop nginx
[root@centos1 nginx-1.6.2] # nginx
3. Check the listening port of nginx, or access it through a browser
[root@centos1 nginx-1.6.2] # netstat-anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
Tcp 0 0 0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0 of the LISTEN.
3. Reload nginx
[root@centos1 nginx-1.6.2] # killall-s HUP nginx
4. Exit nginx
[root@centos1 nginx-1.6.2] # killall-s QUIT nginx
Understand the configuration file nginx.conf of nginx
Description: the nginx.conf file contains three parts of configuration, namely the global configuration, the Icano event configuration and the HTTP configuration.
1. Global configuration
# user nobody; / / user defaults to nobody
Worker_processes 1; / / the number of working processes, which can be specified according to the total number of cpu cores
# location of error_log logs/error.log;// error log file
# location of pid logs/nginx.pid; / / PID file
2.I/O event configuration
Events {
Use epoll / / use the epoll model
Worker_connections 4096; each process handles 4096 process connections
}
The number of connections provided by the nginx service is the number of working processes x the number of connections provided by each process
3.HTTP configuration to complete the setup of the web site
Http {
Include mime.types
Default_type application/octet-stream
Log_format main'$remote_addr-$remote_user [$time_local] "$request" / / remove the preceding #
'$status $body_bytes_sent' $http_referer'/ / remove the preceding #
'"$http_user_agent"$http_x_forwarded_for"; / / remove the preceding #
Access_log logs/access.log main; / / remove the previous #
Sendfile on
# tcp_nopush on
# keepalive_timeout 0
Keepalive_timeout 65
# gzip on
Server {
Listen 80
Server_name localhost
# charset koi8-r
# access_log logs/host.access.log main
Location / {
Root html
Index index.html index.htm
}
Location / status {/ / access location is / status
Stub_status on;// turns on the status statistics function
Access_log off;// turns off logging at this location
}
# error_page 404 / 404.html
# redirect server error pages to the static page / 50x.html
#
Error_page 500 502 503 504 / 50x.html
Location = / 50x.html {
Root html
}
}
4. After modifying the configuration file, reload the configuration file
[root@centos1 nginx-1.6.2] # killall-s HUP nginx
Fourth, build a virtual web host based on domain name.
1. Prepare the website directory and test files
[root@centos1 nginx-1.6.2] # mkdir-p / var/www/benet
[root@centos1 nginx-1.6.2] # echo "www.benet.com" > / var/www/benet/index.html
[root@centos1 nginx-1.6.2] # mkdir-p / var/www/accp
2. [root@centos1 nginx-1.6.2] # echo "www.accp.com" > / var/www/accp/index.html
The virtual host is configured in the server {} zone, where each server {} region represents a web site configuration, specifying its own site name, listening address, site root, access log, etc., and then reloading the configuration
Omit part of the content
{
Server {
Listen 80
Server_name www.benet.com
Charset utf-8
Access_log logs/benet.access.log main
Location / {
Root / var/www/benet
Index index.html index.htm
}
Location / status {
Stub_status on
Access_log off
}
Error_page 500 502 503 504 / 50x.html
Location = / 50x.html {
Root html
}
}
Server {
Listen 80
Server_name www.accp.com
Charset utf-8
Access_log logs/accp.access.log main
Location / {
Root / var/www/accp
Index index.html index.htm
}
Location / status {
Stub_status on
Access_log offm
}
Error_page 500 502 503 504 / 50x.html
Location = / 50x.html {
Root html
}
}
}
3. Reload
[root@centos1 nginx-1.6.2] # killall-s QUIT nginx
[root@centos1 nginx-1.6.2] # nginx
4. test
V. Construction of LNMP architecture and application deployment
1. Install mysql database (slightly, start the mysql server directly)
two。 Install the php parsing environment
Description: newer capital preservation (e.g. 5.3) php has its own FPM (fastCGI Process Manager FastCGI process Manager) module, which is used to manage php parsing instances and optimize parsing efficiency. Need to enable-- enable-fpm to enable this module
(1) compile and install php
[root@centos1 ~] # yum-y install gd libxml2-devel libjpeg-devel libpng-devel
[root@centos1~] # cd / usr/src/php-5.3.28
[root@centos1 php-5.3.28] # / configure-- prefix=/usr/local/php5-- with-gd-- with-zlib-- with-mysql=/usr/local/mysql-- with-config-file-path=/usr/local/php5-- enable-mbstring-- enable-fpm-- with-jpeg-dir=/usr/lib
[root@centos1 php-5.3.28] # make & & make install
(2) Adjustment after installation
[root@centos1 php-5.3.28] # cp php.ini-development / usr/local/php5/php.ini
[root@centos1 php-5.3.28] # ln-s / usr/local/php5/bin/* / usr/local/bin
[root@centos1 php-5.3.28] # ln-s / usr/local/php5/sbin/* / usr/local/sbin
[root@centos1 php-5.3.28] #
3. Configure nginx to support php environment
There are two ways to get nginx to support php
Act as an intermediary to transfer web requests to access php pages to other servers (lamp) for processing
Call the native php environment by using php's FPM module
(1) enable the php-fpm process
[root@centos1 vod] # useradd-M-s / sbin/nologin php
① modifies php-fpm.conf configuration file, modifies relevant parameters, and then starts the php-fpm process. Php-fpm listens on port 9000 of this machine by default.
Pid = run/php-fpm.pid / / confirm the location of the pid file
User = php / / running user
Group = php// running group
Pm.start_servers = 20max / number of processes started at startup
Pm.min_spare_servers = 5max / minimum number of idle processes
Pm.max_spare_servers = 35 / / maximum number of idle processes
Pm.max_children = 50max / maximum number of child processes
② starts php-fpm
[root@centos1 etc] # / usr/local/sbin/php-fpm
(2) configure nginx: fully support php parsing
Note: no matter which parsing method is used, it needs to be configured in server.
[root@centos1 Desktop] # vim / usr/local/nginx/conf/nginx.conf
.
Server {
Listen 80
Server_name www.lxf.com
Charset utf-8
Access_log logs/vod.access.log main
Location / {
Root / var/www/lxf
Index index.html index.php
}
Location ~\ .php$ {/ / access the configuration section of the .php page
The root of the root / var/www/lxf;//php page
Fastcgi_pass 127.0.0.1 9000; / / php-fpm listening address
Fastcgi_index index.php;//php Home Page name
Include fastcgi.conf;//fastcgi module configuration
}
}
}
[root@centos1 vod] # killall-s QUIT nginx
[root@centos1 vod] # nginx
3) php page access test
L [root@centos1 vod] # mysqladmin-u root-p password '123456'
L # service mysqld start / / start the database
Create a test page test.php under / var/www/lxf
Vim / var/www/lxf/test.php
Verify:
VI. Application of LNMP platform-deployment of Sky Network Movie system
1. Download and deploy the program code
[root@centos1] # unzip SKYUC_3.4.2_for_php5.3.zip-d / usr/src
[root@centos1 ~] # cd / usr/src/SKYUC.v3.4.2.SOURCE/
[root@centos1 SKYUC.v3.4.2.SOURCE] # mv wwwroot/ / var/www/lxf/skyuc
[root@centos1 SKYUC.v3.4.2.SOURCE] # cd / var/www/vlxf/skyuc/
[root@centos1 skyuc] # chown-R php:php admincp/ data/ templates/ upload/
[root@centos1 skyuc] #
two。 Create a database
In order to reduce the risk of web application to database, it is recommended to set up a dedicated database and authorized user [root@centos1 skyuc] # mysql-u root-p
Mysql > create database skyucdb
Mysql > grant all on skyucdb.* to runskyuc@localhost identified by 'sky@uc123'
Verify:
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.