Because Nginx boot is not convenient, so we need to manually compile a Nginx startup script
[Email protected] ~]# Vim/etc/init.d/nginx #加入以下内容
#!/bin/bash
# Chkconfig:-30 21
# Description:http Service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
Nginx_sbin= "/usr/local/nginx/sbin/nginx"
nginx_conf= "/usr/local/nginx/conf/nginx.conf"
Nginx_pid= "/usr/local/nginx/logs/nginx.pid"
Retval=0
Prog= "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: $ {start|stop|reload|restart|configtest}"
Retval=1
Esac
Exit $RETVAL
-----------------------------------------------------------------------
After saving, change the permissions:
[[email protected] ~]# chmod 755/etc/init.d/nginx # Change permissions
[Email protected] ~]# chkconfig--add nginx #加入到服务列表
[Email protected] ~]# chkconfig nginx on #开机启动
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/89/B4/wKiom1gaAoTQLZKpAACEe2bKy8o506.jpg "title=" Ng3.jpg "alt=" Wkiom1gaaotqlzkpaacee2bky8o506.jpg "/>
[Email protected] ~]# service Nginx configtest #检查配置文件有没有问题
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
---------------------------------------------------------------------------
Change Nginx configuration file
[Email protected] ~]# Cp/usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/nginx.conf.bak
[Email protected] ~]# >/usr/local/nginx/conf/nginx.conf #清空nginx. conf configuration file
[[email protected] ~]# vim/usr/local/nginx/conf/nginx.conf # Write to the following configuration
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;
# Note This parenthesis and this sentence include vhosts/*.conf;
--------------------------------------------------------------------
[[email protected] ~]#/USR/LOCAL/NGINX/SBIN/NGINX-T # check Nginx compilation
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
[Email protected] ~]# cd/usr/local/nginx/conf/
[[email protected] conf]# mkdir vhosts #创建 vhosts Directory
[Email protected] conf]# CD vhosts/
[[email protected] vhosts]# Vim default.conf # Edit default.conf, write the following
Server
{
Listen default_server;
server_name localhost;
Index index.html index.htm index.php;
root/tmp/1233; #黙认的虚拟主机设置为 empty, access is going to be 403, as
Deny all;
The following comments or books are not used except
# 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;
# }
}
Niginx start (Be sure to check if Nginx starts properly)
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/89/F0/wKiom1gh1SrCayJaAADsfLkYDoM728.jpg "title=" Ng4.jpg "alt=" Wkiom1gh1srcayjaaadsflkydom728.jpg "/>
[[email protected] vhosts] #mkdir/tmp/1223 #创建这个目录
[Email protected] vhosts]#/usr/local/nginx/sbin/nginx-t #编译完检查
[Email protected] vhosts]#/etc/init.d/nginx Reload #重新加载配置文件
Reloading Nginx: [OK]
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/F1/wKiom1gh3uvSOUmeAAEkOGBP6N4783.jpg "title=" Ng5.jpg "alt=" Wkiom1gh3uvsoumeaaekogbp6n4783.jpg "/>
The following conditions can be accessed to access the MO host to reflect
[[email protected] vhosts]# curl localhost
<! DOCTYPE html>
<title>welcome to Nginx!</title>
<style>
Body {
Width:35em;
margin:0 Auto;
Font-family:tahoma, Verdana, Arial, Sans-serif;
}
</style>
<body>
<p>if you see this page, the Nginx Web server is successfully installed and
Working. Further configuration is required.</p>
<p>for online documentation and support for refer to
<a href= "http://nginx.org/" >nginx.org</a>.<br/>
Commercial support was available at
<a href= "http://nginx.com/" >nginx.com</a>.</p>
<p><em>thank for using nginx.</em></p>
</body>
Landlord in the writing of another host when, did not achieve 502 of the state, somehow.
The following test.com sample files
Server
{
Listen 80;
server_name test.com;
Index index.html index.htm index.php;
root/data/www;
Location ~ \.php$ {
Include Fastcgi_params;
#fastcgi_pass Unix:/tmp/php-fcgi.sock;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/www$fastcgi_script_name;
}
}
[Email protected] vhosts]# vim test.com
[Email protected] vhosts]# curl-x127.0.0.1:80 test.com
<body bgcolor= "White" >
<center>
</body>
This article is from the "Cbo#boy_linux Road" blog, make sure to keep this source http://20151213start.blog.51cto.com/9472657/1870855
LNMP Nginx startup scripts and configuration files