使用root安装nginx后使用非root运行方法

前言

总用root运行太麻烦。注意的是,非root启动1024如下端口会报错,须要修改,注意服务。(奇怪,怎么这里能够写服务,上一篇又不行的?)html

安装nginx

下载

http://nginx.org/packages/centos/7/x86_64/RPMS/nginx

nginx-1.12.1-1.el7.ngx.x86_64.rpm,不下载nginx-1.12.2-1.el7_4.ngx.x86_64.rpmweb

由于须要试试1.12.1是否还会报整数溢出漏洞。ubuntu

查看操做系统

radhat或centos存在: /etc/redhat-release 这个文件【 命令 cat /etc/redhat-release 】 ubuntu存在 : /etc/lsb-release 这个文件 【命令 cat /etc/lsb-release 】 debian存在 cat /etc/debian_version 这个文件 Slackware存在 cat /etc/slackware_version 这个文件 参考: http://www.javashuo.com/article/p-ftfraknc-mp.htmlcentos

查看版本

根据版本选择下载的rpm包。版本是7,是64位的。app

查看centos版本:webapp

[webapp@pay-app-sever ~]$ uname -a
Linux pay-app-sever 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ cat /etc/issue
\S
Kernel \r on an \m
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ cat /proc/version
Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ uname -r
3.10.0-327.el7.x86_64
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=aa7ff68f13de25936a098016243ce57c3c982e06, stripped
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ getconf LONG_BIT
64
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ getconf WORD_BIT
32
https://blog.csdn.net/shuaigexiaobo/article/details/78030008

安装

须要使用root用户。测试

[root@pay-app-sever nginx]# rpm -ivh nginx-1.12.1-1.el7.ngx.x86_64.rpm
warning: nginx-1.12.1-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:nginx-1:1.12.1-1.el7.ngx         ################################# [100%]
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

---------------------------------

赋权webapp用户

chown webapp /var/log/nginx
chown webapp /var/log/nginx/*
chown webapp /etc/nginx
chown webapp /etc/nginx/*
chown webapp /etc/nginx/conf.d/*
chown webapp /usr/sbin/nginx
chown webapp /var/cache/nginx
mkdir /var/run/nginx
chown webapp  /var/run/nginx

vi /etc/nginx/nginx.conf
#pid        /var/run/nginx.pid;
pid        /var/run/nginx/nginx.pid;

vi /etc/nginx/conf.d/default.conf
#    listen       80;
    listen       18010;

启动

[webapp@pay-app-sever ~]$ nginx
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
[webapp@pay-app-sever ~]$ 
[webapp@pay-app-sever ~]$ ps -ef|grep nginx
webapp    84434      1  0 11:36 ?        00:00:00 nginx: master process nginx
webapp    84435  84434  0 11:36 ?        00:00:00 nginx: worker process

成功访问

http://0.23.12.109:8010/ui

目录

  1. 配置所在目录:/etc/nginx/
  2. PID目录:/var/run/nginx/nginx.pid
  3. 错误日志:/var/log/nginx/error.log
  4. 访问日志:/var/log/nginx/access.log
  5. 默认站点目录:/usr/share/nginx/html

经常使用命令

  1. 启动nginx:nginx
  2. 重启nginx(不杀进程,从新加载nginx.conf):killall -HUP nginx
  3. 中止nginx:nginx -s stop
  4. 测试nginx配置:nginx -t
相关文章
相关标签/搜索