Nginx startup scripts and configuration files

Source: Internet
Author: User

1. Configure Startup scripts

Vim/etc/init.d/nginx

Write the following:

#!/bin/bash# chkconfig: - 30 21# description: http service.# source  function library. /etc/init.d/functions# nginx settingsnginx_sbin= "/usr/local/nginx/ Sbin/nginx "nginx_conf="/usr/local/nginx/conf/nginx.conf "nginx_pid="/usr/local/nginx/logs/nginx.pid "RETVAL= 0prog= "Nginx" Start ()  {        echo -n $ "Starting $ prog:  "        mkdir -p /dev/shm/nginx_temp         daemon  $NGINX _sbin -c  $NGINX _conf         RETVAL=$?        echo         return  $RETVAL}stop ()  {        echo  -n $ "stopping  $prog: "         killproc -p   $NGINX _pid  $Nginx_sbin -term        rm -rf /dev/shm/nginx_temp         RETVAL=$?        echo         return  $RETVAL}reload () {         echo -n $ "reloading  $prog: "          killproc -p  $NGINX _pid  $NGINX _sbin -hup         retval=$?        echo         return  $RETVAL}restart () {        stop         start}configtest () {     $NGINX _sbin -c  $NGINX _conf - t    return 0}case  "$"  in  start)          start        ;;   stop)         stop         ;;   reload)         reload         ;;   restart)         restart         ;;   configtest)         configtest         ;;   *)         echo $ "usage: $0 {start|stop| Reload|restart|configtest} "        RETVAL=1esacexit  $RETVAL

2. Change permissions

chmod 755/etc/init.d/nginx

3. Join the boot and start

Chkconfig--add Nginx
Chkconfig Nginx on

4. Change Nginx Configuration

First, empty the original configuration file:

>/usr/local/nginx/conf/nginx.conf

Modifying a configuration file

Vim/usr/local/nginx/conf/nginx.conf
User nobody nobody;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log  crit;pid /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events{     use epoll;    worker_connections 6000;} http{    include mime.types;    default_type application/ Octet-stream;    server_names_hash_bucket_size 3526;    server_ names_hash_max_size 4096;    log_format combined_realip  ' $remote _addr  $http _x_forwarded_for [$time _local] '      ' $host   ' $request _uri '   $status '      "$http _referer"   "$http _user_agent" ';    sendfile on;     tcp_nopush on;    keepalive_timeout 30;     client_header_timeout 3m;    cliEnt_body_timeout 3m;    send_timeout 3m;    connection_pool_ Size 256;    client_header_buffer_size 1k;    large_client_ Header_buffers 8 4k;    request_pool_size 4k;    output _buffers 4 32k;    postpone_output 1460;    client_max_ Body_size 10m;    client_body_buffer_size 256k;    client_ body_temp_path /usr/local/nginx/client_body_temp;    proxy_temp_path /usr/local/ nginx/proxy_temp;    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;     fastcgi_intercept_errors on;    tcp_nodelay on;     gzip on;    gzip_min_length 1k;    gzip_buffers 4  8k;    gzip_comp_level 5;    gzip_http_version 1.1;     gzip_types text/plain application/x-javascript text/css text/htm application/ xml

Include vhost/*.conf;

}

5. Create a virtual host configuration file

Cd/usr/local/nginx

mkdir vhosts

CD vhosts

Vim default.conf

server{listen default;    server_name localhost;    Index index.html index.htm index.php;    root/usr/local/nginx/html;        Location ~ \.php$ {include fastcgi_params;        Fastcgi_pass Unix:/tmp/php-fcgi.sock;        Fastcgi_index index.php;    Fastcgi_param Script_filename/usr/local/nginx/html$fastcgi_script_name; }}


Check for configuration files with or without errors

/usr/local/nginx/sbin/nginx-t

6. Test PHP parsing

Cd/usr/local/nginx/html

Vim 2.php

<?php

echo "Test php successful"

?>

Restart Nginx Service

Service Nginx Restart

Success with browser access is shown below

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/0B/wKioL1dJDbuBM5wuAAA96us7UzY506.jpg-wh_500x0-wm_3 -wmp_4-s_1992663856.jpg "title=" php2.jpg "alt=" Wkiol1djdbubm5wuaaa96us7uzy506.jpg-wh_50 "/>

This article is from the "愺 Burgundy pounding his 豩" blog, please be sure to keep this source http://riverxyz.blog.51cto.com/533303/1784004

Nginx startup scripts and configuration files

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.