LNMP-nginxの起動スクリプト、コンフィギュレーションファイル

デフォルトの起動モードのbinディレクトリに移動し、nginxの追加や、サービスを開始するには、変数を設定し、我々はまた、init.dディレクトリに置かれ、独自の起動スクリプトを書くことができ、それが甲斐サービスから起動してみましょう!
 
1:スタートアップスクリプトを書きます
[ルートGHS @〜]#のVimの/etc/init.d/nginx
 以下は、設定ファイルに追加されます
#!/ binに/ bashの
#1のchkconfig: - 30 21
#説明:HTTPサービス。
#ソース機能ライブラリ
/etc/init.d/functions
#nginxの設定
 
NGINX_SBIN = "は/ usr / local / nginxの/ sbinに/ nginxの"
NGINX_CONF = "は/ usr / local / nginxの/ confに/ nginx.conf"
NGINX_PID = "は/ usr / local / nginxの/ログ/ nginx.pid"
RETVAL = 0
PROG = "nginxの"
 
{開始()
        $ -nエコー "$ progの開始を:"
        ます。mkdir -pは/ dev / shmを/ nginx_temp
        デーモン$ NGINX_SBIN -c $ NGINX_CONF
        RETVAL = $?
        エコー
        リターン$ RETVAL
}
 
やめる() {
        -n $エコー "$ progの停止を:"
        killproc -p $ NGINX_PID $ NGINX_SBIN -TERM
        RM -rfは/ dev / shmを/ nginx_temp
        RETVAL = $?
        エコー
        リターン$ RETVAL
}
 
リロード(){
        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 "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
 
exit $RETVAL
 
2:设置权限
[root@ghs ~]# chmod 755 /etc/init.d/nginx
 
3:加入系统服务,并开机自动启动服务
[root@ghs ~]# chkconfig --add nginx
 [root@ghs ~]# chkconfig nginx on
 
5:测试启动脚本是否能启动
[root@ghs ~]# service nginx start
正在启动 Nginx:                                           [确定]
 
 
 
二、通常情况下,服务器上Nginx服务,都会同时跑一个或者N+个网站,这时候需要我们运维人员自定义编写conf文件,Nginx默认配置文件是没有开启虚拟主机配置,加入include指定虚拟主机conf文件存放路径,开启虚拟主机!
 
1:编写conf文件
[root@ghs ~]# 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 vhosts/*.conf;
 }
 
2:切换目录
[root@ghs nginx]# cd /usr/local/nginx/conf/
 
3:创建虚拟主机目录vhosts
[root@ghs conf]# mkdir vhosts
 
4:编写配置虚拟主机文件
[root@ghs vhosts]# vim /vhosts/default.conf
 
server
{
    listen 80 default_server;
    server_name localhost;
    index index.html index.htm index.php;
    root /tmp/123;这个是不存在的实验用的
 
 
}
 
5:创建WEB服务目录
[root@ghs vhosts]# cd /tmp/
[root@ghs tmp]# mkdir 123
 
 
6:命令加-t参数,检查虚拟主机配置是否有误
[root@ghs vhosts]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
 
 
7:重新加载服务
[root@ghs vhosts]# nginx -s reload
 
 
8:curl命令测试
[root@ghs vhosts]# curl localhost
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>

 

 

 

おすすめ

転載: www.cnblogs.com/douyi/p/11578873.html