Linux使用普通账户管理Nginx的方法
admin
2023-02-21 14:00:05
0

创建账户

useradd duser

Nginx编译安装

#下载并解压缩nginx包
tar zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
#编译安装
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/tmp/echo-nginx-module

make

make install

说明⚠️:其中,如不需要echo模块,将最后一个选项去掉,如需要echo模块,从github上面拉到指定位置

配置 nginx.conf 文件

cd /etc/nginx/
cp nginx.conf nginx.conf_bak
#cat nginx.conf
user  duser  duser;

#Single core
worker_processes  2;

#Multicore
#worker_processes     8;
#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  10240;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$http_host"'
                      '$request_time $upstream_response_time $pipe - $upstream_addr';

    log_format  post_format $request_body;

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  120;
    proxy_connect_timeout 600;
    proxy_send_timeout 600s;
    proxy_read_timeout 600s;

    #gzip  on;

    include /etc/nginx/http.d/*.conf;
}

stream {
    log_format proxy '$remote_addr [$time_local] '
                     '$protocol $status $bytes_sent $bytes_received '
                     '$session_time "$upstream_addr" '
                     '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
    access_log /var/log/nginx/stream.access.log proxy;

    include /etc/nginx/stream.d/*.conf;
}
#创建更改http,tcp服务目录和权限
mkdir /etc/nginx/http.d
mkdir /etc/nginx/stream.d
chmod 777 /etc/nginx/http.d
chmod 777 /etc/nginx/stream.d

修改 nginx 使用权限

chmod u+s /usr/sbin/nginx

测试

#启动nginx
nginx
#查看nginx服务
ps -ef |grep nginx
root     22828     1  0 14:17 ?        00:00:00 nginx: master process nginx
duser    23062 22828  0 14:50 ?        00:00:00 nginx: worker process
duser    23063 22828  0 14:50 ?        00:00:00 nginx: worker process
duser    23064 22828  0 14:50 ?        00:00:00 nginx: worker process
duser    23065 22828  0 14:50 ?        00:00:00 nginx: worker process
root     23396 23364  0 16:20 pts/2    00:00:00 grep --color=auto nginx
#先切到duser账户下
su - duser
#自定义一个http服务
cat /etc/nginx/http.d/test.conf
server {
        listen       8080;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
}
#平滑重启nginx
nginx -t
nginx -s reload

相关内容

热门资讯

【今日要闻】“天天爱泰州麻将.... 网上科普关于“天天爱泰州麻将有没有挂”话题很是火热,小编也是针对天天爱泰州麻将作*弊开挂的方法以及开...
我来教教您“新皇豪牛牛.怎么开... 网上科普关于“新皇豪牛牛有没有挂”话题很是火热,小编也是针对新皇豪牛牛作*弊开挂的方法以及开挂对应的...
【今日要闻】“德州之夜.开挂器... 有 亲,根据资深记者爆料德州之夜是可以开挂的,确实有挂(咨询软件无需打开...
特朗普提名特战副司令执掌南方司... 美国国防部长赫格塞思19日宣布,美国总统特朗普提名美军特种作战司令部副司令弗朗西斯·多诺万出任南方司...
玩家分享攻略“皇豪众娱牛牛.可... 有 亲,根据资深记者爆料皇豪众娱牛牛是可以开挂的,确实有挂(咨询软件无需...
【今日要闻】“乐酷炸金花.辅助... 有 亲,根据资深记者爆料乐酷炸金花是可以开挂的,确实有挂(咨询软件无需打...
【第一财经】“中至万年麻将.有... 家人们!今天小编来为大家解答中至万年麻将透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里...
玩家分享攻略“麻友圈2挪来挪去... 网上科普关于“麻友圈2挪来挪去有没有挂”话题很是火热,小编也是针对麻友圈2挪来挪去作*弊开挂的方法以...
SpaceX罕见披露:一卫星疑... 转自:环球时报 据路透社19日报道,美国太空探索技术公司(SpaceX)表示,其旗下“星链”(Sta...
【今日要闻】“新三哥玩.可以开... 网上科普关于“新三哥玩有没有挂”话题很是火热,小编也是针对新三哥玩作*弊开挂的方法以及开挂对应的知识...