Bereitstellen eines Hochleistungswebservers – Nginx

1、install basic independent packages

yum -y install gcc openssl-devel pcre-devel zlib-devel

2、deploy nginx

useradd nginx -s /sbin/nologin #add nginx user

tar zxvf nginx-1.2.7.tar.gz #uncompress nginx tar.gz package.

cd nginx-1.2.7

./konfigurieren \

–user=nginx \ # user is nginx

–Gruppe=nginx \ #user group is nginx

prefix=/usr/local/nginx/ \ # nginx home path

–with-http_stub_status_module \

with-http_ssl_module #ssl module

# for more parameter,you can refoer to this command

./konfigurieren –Hilfe

nginx path prefix: “/usr/local/nginx

nginx binary file: “/usr/local/nginx/sbin/nginx

nginx configuration prefix: “/usr/local/nginx/conf

nginx configuration file: “/usr/local/nginx/conf/nginx.conf

nginx pid file: “/usr/local/nginx/logs/nginx.pid

nginx error log file: “/usr/local/nginx/logs/error.log

nginx http access log file: “/usr/local/nginx/logs/access.log

nginx http client request body temporary files: “client_body_temp

nginx http proxy temporary files: “proxy_temp

nginx http fastcgi temporary files: “fastcgi_temp

 

machen & make install

 

check whether the configuration in nginx is correct or not

after installation.

/usr/local/nginx/sbin/nginx –v

 

3、configure nginx

cd /usr/local/nginx/conf/

rm -rf nginx.conf

vim nginx.conf

paste the following configuration to nginx.conf

Benutzer nginx nginx; #user and user group

worker_processes 8; #process amount when nginx start

error_log logs/nginx_error.log crit; #error log and log level

pid /usr/local/nginx/nginx.pid; #PID file path

worker_rlimit_nofile 51200;

Veranstaltungen

{

epol verwenden; # epoll module

worker_connections 51200; #maximum allowed connection of each process.

}

http

{

include mime.types;

default_type application/octet-stream;

#charset gb2312;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

sendfile on;

tcp_nopush ein;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

gzip an;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain application/x-javascript text/css application/xml;

gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;

Server

{

Hör mal zu 80;

server_name localhost; #hostname or server name

index index.html index.htm index.php; # default main page name.

root /usr/local/nginx/html; #root directory in website

Ort / {

root html;

index index.html index.htm;

}

limit_conn crawler 20;

#FastCGI can support PHP

Lage ~ .*\.(php|php5)?$

{

#fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass 127.0.0.1:9000; #fastcgi listen port 9000

fastcgi_index index.php;

include fcgi.conf; #fastcg configuration file.

}

#for a type of static file , you can set long cache time

Lage ~ .*\.(gif|jpg|JPEG|png|bmp|swf|js|CSS)$

{

läuft 30d ab;

}

#Protokollformat

log_format Zugriff ‘$remote_addr – $remote_user [$time_local] “$Anfrage” ‘

‘$status $body_bytes_gesendet “$http_referer” ‘

‘”$http_user_agent” $http_x_forwarded_for’;

access_log logs/access.log access;

}

}

speichern und schließen!

 

NOTE : this is a baisc confifguration fileyou need to edit it again if you would like to

configure other featuer.

4、start nginxand check the working status

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ps -ef | grep nginx

netstat -nltp | grep 80

links 127.0.0.1 # wenn “welcome to nginx!” erschien, this indicat nginx startup successfully

or you can input “localhost” in url bar of web brower , if you have seenwelcome to nginx!”

It means that nginx starup successfully

Hinterlasse eine Antwort