Nginx常用命令:

启动nginx服务

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
[root@localhost ~]# service nginx start
[root@localhost ~]# systemctl start nginx.service
[root@localhost ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf      # nginx安装目录 -c nginx.conf配置文件目录。
[root@localhost sbin]# ./nginx      # 进入/usr/local/nginx/sbin/ 即nginx的安装目录下。通过 ./nginx 启动nginx服务。
# 启动nginx服务:参数 “-c” 指定了配置文件的路径,如果不加 “-c” 参数,Nginx 会默认加载其安装目录的 conf 子目录中的 nginx.conf 文件。

停止nginx服务

[root@localhost ~]# service nginx stop
[root@localhost ~]# systemctl stop nginx.service
[root@localhost sbin]# ./nginx -s stop    进入 nginx 的安装目录。通过 ./nginx -s stop 停止nginx服务。先查出nginx进程id,再使用kill命令强制杀掉进程。
[root@localhost sbin]# ./nginx -s quit    进入 nginx 的安装目录。通过 ./nginx -s quit 停止nginx服务。先等待nginx进程处理任务完毕后再停止。

重启nginx服务

[root@localhost ~]# service nginx restart
[root@localhost ~]# systemctl restart nginx.service
[root@localhost sbin]# ./nginx -s quit         # 对 nginx 进行先停止再启动。
[root@localhost sbin]# ./nginx

重载nginx配置文件

[root@localhost ~]# service nginx reload
[root@localhost ~]# systemctl reload nginx.service
[root@localhost sbin]# ./nginx -s reload          进入nginx的安装目录。通过 ./nginx -s reload 重新加载nginx配置文件。
# 当 nginx的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止再启动 nginx,即可将配置信息在 nginx 中生效。

其他nginx命令

# 查看nginx安装目录
[root@localhost ~]# ps -ef | grep nginx
# 查看nginx.conf配置文件目录,验证nginx配置文件是否正确。进入nginx安装目录下,执行./nginx -t命令。
[root@localhost sbin]# ./nginx -t      

Nginx配置文件:

重定向问题

server {
    listen 80;
    listen 443 ssl;
    server_name www.adspush.com adspush.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root C:/wwwroot/www.adspush.com;
		
    #REWRITE-START
    include rewrite/www.adspush.com/*.conf;
    #REWRITE-END

    #redirect 重定向
    # include redirect/www.fpaiseo.com/*.conf;
    if ($host ~ '^fpaiseo.com'){
        return 301 http://www.fpaiseo.com/$request_uri;
    }
}

  

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄