启动
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-c制定配置文件的路径,不加nginx会自动加载默认路径的配置文件。
平滑重启
/usr/local/nginx/sbin/nginx –s reload
kill -HUP pid
检查配置
nginx -t -c /usr/nginx/conf/nginx.conf
======================================
http {
server {
listen 80;
server_name www.domain1.com;
access_log logs/domain1.access.log main;
location / {
index index.html;
root /var/www/domain1.com/htdocs;
}
}
server {
listen 80;
server_name www.domain2.com;
access_log logs/domain2.access.log main;
location / {
index index.html;
root /var/www/domain2.com/htdocs;
}
}
}
=======================================
server {
# Replace this port with the right one for your requirements
# 根据你的需求改变此端口
listen 80; #could also be 1.2.3.4:80 也可以是1.2.3.4:80的形式
# Multiple hostnames seperated by spaces. Replace these as well.
# 多个主机名可以用空格隔开,当然这个信息也是需要按照你的需求而改变的。
server_name star.yourdomain.com *.yourdomain.com www.*.yourdomain.com;
#Alternately: _ *
#或者可以使用:_ * (具体内容参见本维基其他页面)
root /PATH/TO/WEBROOT/$host;
error_page 404 http://yourdomain.com/errors/404.html;
access_log logs/star.yourdomain.com.access.log;
location / {
root /PATH/TO/WEBROOT/$host/;
index index.php;
}
# serve static files directly
# 直接支持静态文件 (爱月说:???从配置上看来不是直接支持啊~有问题有问题~)
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires 30d;
}
location ~ .php$ {
# By all means use a different server for the fcgi processes if you need to
# 如果需要,你可以为不同的FCGI进程设置不同的服务信息
fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /PATH/TO/WEBROOT/$host/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
}
location ~ /.ht {
deny all;
}
}
==================================
基于IP访问
http {
server {
listen 172.16.18.1:80;
server_name www.aolens.com;
root /data/webapps/www;
index index.html;
}
server {
listen:172.16.18.5:80;
server_name web.aolens.com;
root /data/webapps/web;
index index.html;
} }
==============================================
http://yuhongchun.blog.51cto.com/1604432/1565222
YUM源来安装Nginx
==================================================
Apache和Nginx如何关闭日志 http://www.phpstudy.net/a.php/175.html