In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The knowledge of this article "how to deploy nginx, php and virtual hosts in the CentOS environment" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to deploy nginx, php and virtual hosts in the CentOS environment" article.
Os environment: centos 6.1
Nginx:nginx-1.2.2
Php:php5.3.14
0. Install dependency package
The copy code is as follows:
Yum install openssl-devel pcre-devel zlib-devel libjpeg-devel libpng-devel freetype-devel gcc make
1. Add www users to execute nginx
The copy code is as follows:
Useradd-m-r-s / sbin/nologin-d / opt/web/ www
2. Create a temporary directory
The copy code is as follows:
Mkdir-p / var/tmp/nginx/client/
Mkdir-p / var/tmp/nginx/proxy/
Mkdir-p / var/tmp/nginx/fcgi/
3. Download the latest stable version of nginx source code
The copy code is as follows:
Cd / usr/local/src/
Wget http://nginx.org/download/nginx-1.2.2.tar.gz
4. Decompress, compile, install
The copy code is as follows:
Tar vxzf nginx-1.2.2.tar.gz
Cd nginx-1.2.2/
. / configure\
-- prefix=/opt/web/nginx\
-- error-log-path=/var/log/nginx/error.log\
-- pid-path=/var/run/nginx/nginx.pid\
-- lock-path=/var/lock/nginx.lock\
-- user=www\
-- group=www\
-- with-http_ssl_module\
-- with-http_stub_status_module\
-- with-http_gzip_static_module\
-- http-log-path=/var/log/nginx/access.log\
-- http-client-body-temp-path=/var/tmp/nginx/client/\
-- http-proxy-temp-path=/var/tmp/nginx/proxy/\
-- http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\
-- http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/
Make
Make install
5. Configure nginx
The copy code is as follows:
Vim / opt/web/nginx/conf/nginx.conf
# specify the startup user:
User www www
# the number of processes, which the nginx author thinks is fine, can be modified according to his own traffic.
Worker_processes 1
# set error log:
# error_log logs/error.log notice
# error_log logs/error.log info
Error_log / var/log/nginx/error.default.log
Pid / opt/web/nginx/nginx.pid
Events {
Use epoll
Worker_connections 1024
}
Http {
Charset utf-8
Include mime.types
Default_type application/octet-stream
# 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 logs/access.log main
Sendfile on
Tcp_nopush on
Tcp_nodelay on
# keepalive_timeout 0
Keepalive_timeout 65
Gzip on
Gzip_min_length 1000
Gzip_proxied any
Gzip_types text/plain text/css text/xml
Application/x-javascript application/xml
Application/atom+xml text/javascript
Server {
Listen 80
Server_name localhost
Charset utf-8
# access_log logs/host.access.log main
Location / {
Root html
Index index.html index.htm
}
# 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
}
# proxy the php scripts to apache listening on 127.0.0.1:80
#
# location ~\ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the php scripts to fastcgi server listening on 127.0.0.1:9000
#
Location ~\ .php$ {
Root html
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
# fastcgi_param script_filename / scripts$fastcgi_script_name
# include fastcgi_params
Include fastcgi.conf
}
# deny access to .htaccess files, if apache's document root
# concurs with nginx's one
#
Location ~ /\ .ht {
Deny all
}
}
# another virtual host using mix of ip-, name-, and port-based configuration
#
# server {
# listen 8000
# listen somename:8080
# server_name somename alias another.alias
# location / {
# root html
# index index.html index.htm
#}
#}
# https server
#
# server {
# listen 443
# server_name localhost
# ssl on
# ssl_certificate cert.pem
# ssl_certificate_key cert.key
# ssl_session_timeout 5m
# ssl_protocols sslv2 sslv3 tlsv1
# ssl_ciphers high:!anull:!md5
# ssl_prefer_server_ciphers on
# location / {
# root html
# index index.html index.htm
#}
#}
Proxy_read_timeout 200
# only retry if there was a communication error, not a timeout
# on the tornado server (to avoid propagating "queries of death"
# to all frontends)
Proxy_next_upstream error
Proxy_set_header x-scheme $scheme
Proxy_set_header x-real-ip $remote_addr
Proxy_set_header host $host
Proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for
# introduce virtual host file
Include / opt/web/nginx/conf/sites/*.conf
}
6. Set up the directory where the virtual machine configuration files are stored
The copy code is as follows:
Mkdir / opt/web/nginx/conf/sites
After this configuration, you need to add a new virtual host directly under the nginx/conf/sites/ directory and add a configuration file.
For example, there is a www.jb51.net domain name.
Create: / opt/web/nginx/conf/sites/www.jb51.net.conf file
The contents are as follows:
The copy code is as follows:
Server {
Listen 80
Client_max_body_size 10m
# multiple domain names are separated by spaces, and the first one is the default
Server_name www.jb51.net jb51.net
Charset utf-8
Index index.html index.htm index.php
# define the root directory
Set $root/ var/webroot/www.jb51.net/
# set site path
Root $root
# prevent directory browsing
Autoindex off
If ($host! = 'www.jb51.net') {
Rewrite ^ / (. *) $/ / www.jb51.net/$1 permanent
}
# prevent .htaccess files from being requested
Location ~ /\ .ht {
Deny all
}
Error_page 404 / 404.html
Index index.html index.htm
Location / uploads/ {
Alias / data/webroot/www.jb51.net/uploads/
}
Try_files $uri @ uwsgi
Location @ uwsgi {
# transfer other requests to uwsgi
Include uwsgi_params
Uwsgi_pass unix:/tmp/360ito_uwsgi.sock
Proxy_set_header x-real-ip $remote_addr
Proxy_set_header host $host
Proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for
# proxy_pass http://localhost:5000;
}
# transfer a request of type php to fastcgi
Location ~\ .php$ {
Root html
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Include fastcgi.conf
}
# access log:
Access_log / var/log/nginx/access.www.jb51.net.log
# load .htaccess rewrite file. Note that variable paths are not supported here.
# cannot be written as include $root/www.jb51.net/.htaccess
# include / var/webroot/www.jb51.net/.htaccess
# if domain name redirection is enabled, other domain names will be automatically redirected to www.jb51.net when an access error occurs
# Note, what I'm saying here is that it only jumps when there is an error in the access, so 301 redirection is not possible here!
Server_name_in_redirect on
}
7. Install the latest version php (php5.3.14)
The copy code is as follows:
Cd / usr/local/src/
Wget http://cn.php.net/get/php-5.3.14.tar.bz2/from/this/mirror
Tar xjvf php-5.3.14.tar.bz2
Cd php-5.3.14
Execute:
The copy code is as follows:
. / buildconf-- force
If you report an error, it may be that your autoconf is not version 2.13, php5.3. Series of bug, you need to install version 2.13 of autoconf:
The copy code is as follows:
Centos: # yum install autoconf213
Debian: # apt-get install autoconf2.13
Set environment variabl
The copy code is as follows:
# centos:
Export php_autoconf= "/ usr/bin/autoconf-2.13"
# debian:
Export php_autoconf= "/ usr/bin/autoconf2.13"
Run:. / buildconf-- force again, and buildconf: autoconf version 2.13 (ok) appears
Is a success
Compile and install php
The copy code is as follows:
. / configure\
-- prefix=/opt/web/php\
-- with-config-file-path=/opt/web/php/etc\
-- with-config-file-scan-dir=/opt/web/php/etc/conf.d\
-- enable-fpm\
-- with-fpm-user=www\
-- with-fpm-group=www\
-- with-mysql=/opt/db/percona-server-5.5.14-rel20.5\
-- with-mysqli=/opt/db/percona-server-5.5.14-rel20.5/bin/mysql_config\
-- with-iconv-dir\
-- with-freetype-dir\
-- with-jpeg-dir\
-- with-png-dir\
-- with-zlib\
-- with-libxml-dir\
-- enable-xml\
-- enable-mbstring\
-- with-gd\
-- enable-gd-native-ttf\
-- with-openssl\
-- enable-inline-optimization
Make & & make install
Cp php.ini-production / opt/web/php/etc/php.ini
Cd / opt/web/php/etc
Cp php-fpm.conf.default php-fpm.conf
Modify php-fpm.conf to enable the following lines, that is, remove the previous semicolon (;)
The copy code is as follows:
Pid = run/php-fpm.pid
Error_log = log/php-fpm.log
Log_level = notice
Listen = 127.0.0.1 9000
Listen.allowed_clients = 127.0.0.1
Listen.owner = www
Listen.group = www
Listen.mode = 0666
User = www
Group = www
Pm = dynamic
Pm.max_children = 50
Pm.start_servers = 5
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
Pm.max_requests = 500,
Env [hostname] = $hostname
Env [path] = / usr/local/bin:/usr/bin:/bin
Env [tmp] = / tmp
Env [tmpdir] = / tmp
Env [temp] = / tmp
8. Start php-fpm
The copy code is as follows:
/ opt/web/php/sbin/php-fpm
Start nginx
The copy code is as follows:
/ opt/web/nginx/sbin/nginx
9. Test it
The copy code is as follows:
Vim / var/webroot/www.jb51.net/tz.php
Import and Save
The copy code is as follows:
10. Enter: http://php.jb51.net/tz.php in the browser address bar
If successful, you can see the information output by phpinfo ()
The above is the content of this article on "how to deploy nginx, php and virtual hosts in the CentOS environment". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
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.