nginx全局塊的user指令的實(shí)現(xiàn)示例
1、user指令
user:用于配置運(yùn)行Nginx服務(wù)器的 worker進(jìn)程
的用戶和用戶組。
語法 | user user[group] |
---|---|
默認(rèn)值 | nobody |
位置 | 全局塊 |
該屬性也可以在編譯
的時候指定,語法如下:
./configure --user=user
./configure --group=group
如果兩個地方都進(jìn)行了設(shè)置,最終生效的是配置文件中的配置。
1.1、進(jìn)入nginx解壓的目錄
[root@localhost conf]# cd /opt/tool/nginx/nginx-1.20.1/ [root@localhost nginx-1.20.1]# pwd /opt/tool/nginx/nginx-1.20.1
1.2、./configure --help
[root@localhost nginx-1.20.1]# ./configure --help --user=USER set non-privileged user for worker processes --group=GROUP set non-privileged group for worker processes
1.3、工作進(jìn)程默認(rèn)是nobody
[root@localhost nginx-1.20.1]# ps -ef | grep nginx root 7337 1 0 18:12 ? 00:00:00 nginx: master process ./nginx nobody 7338 7337 0 18:12 ? 00:00:00 nginx: worker process root 7719 7193 0 18:48 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx-1.20.1]# cat /usr/local/nginx/conf/nginx.conf #user nobody;
2、user指令的使用步驟:
2.1、設(shè)置一個用戶信息"www"
修改nginx.conf配置文件中的#user nobody;為user www;
user www;
[root@localhost sbin]# pwd /usr/local/nginx/sbin [root@localhost sbin]# ./nginx -t nginx: [emerg] getpwnam("www") failed in /usr/local/nginx/conf/nginx.conf:2 nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
發(fā)現(xiàn)配置文件測試失敗,這個時候我們需要創(chuàng)建一個用戶www
2.2、 創(chuàng)建一個用戶
[root@localhost sbin]# useradd www [root@localhost sbin]# ./nginx -t 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
[root@localhost sbin]# ps -ef | grep nginx root 7337 1 0 18:12 ? 00:00:00 nginx: master process ./nginx nobody 7338 7337 0 18:12 ? 00:00:00 nginx: worker process root 8006 7193 0 19:12 pts/0 00:00:00 grep --color=auto nginx
2.3、./nginx -s reload
[root@localhost sbin]# ./nginx -s reload [root@localhost sbin]# ps -ef | grep nginx root 7337 1 0 18:12 ? 00:00:00 nginx: master process ./nginx www 8016 7337 0 19:13 ? 00:00:00 nginx: worker process root 8018 7193 0 19:13 pts/0 00:00:00 grep --color=auto nginx
2.4、創(chuàng)建/root/html/index.html頁面,添加如下內(nèi)容
[root@localhost sbin]# cd /root/ [root@localhost ~]# mkdir html [root@localhost ~]# cd html/ [root@localhost html]# vim index.html <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans^Bserif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <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 please refer to <a rel="external nofollow" >nginx.org</a>.<br/> Commercial support is available at <a rel="external nofollow" >nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> <p><em>I am WWW</em></p> </body> </html>
file:///usr/local/nginx/html/index.html
2.5、修改nginx.conf
location / { root /root/html; index index.html index.htm; }
[root@localhost conf]# pwd /usr/local/nginx/conf [root@localhost conf]# vim nginx.conf [root@localhost conf]# cd ../sbin/ [root@localhost sbin]# ./nginx -t 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 [root@localhost sbin]# ./nginx -s reload
2.6、測試啟動訪問
頁面會報(bào)403拒絕訪問的錯誤
到此這篇關(guān)于nginx全局塊的user指令的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)nginx全局塊user指令內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
nginx 如何實(shí)現(xiàn)if嵌套的方法示例
這篇文章主要介紹了nginx 如何實(shí)現(xiàn)if嵌套的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11如何解決Nginx請求轉(zhuǎn)發(fā)將POST變?yōu)镚ET問題
這篇文章主要介紹了如何解決Nginx請求轉(zhuǎn)發(fā)將POST變?yōu)镚ET問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06ubuntu16.04下徹底卸載nginx的相關(guān)命令
nginx是一款自由的、開源的、高性能的HTTP服務(wù)器和反向代理服務(wù)器;這篇文章主要介紹了ubuntu16.04下徹底卸載nginx的相關(guān)命令,需要的朋友可以參考下2018-12-12Nginx轉(zhuǎn)發(fā)需求querystring轉(zhuǎn)寫示例解析
這篇文章主要為大家介紹了Nginx轉(zhuǎn)發(fā)需求querystring轉(zhuǎn)寫示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08Nginx設(shè)置HttpOnly Secure SameSite參數(shù)解決Cookie信息丟失
本文主要介紹了Nginx中Cookie缺少SameSite屬性的問題,并詳細(xì)解釋了HttpOnly、Secure和SameSite屬性的作用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-11-11