当前位置:   article > 正文

Linux环境下(CentOS 7)安装/卸载nginx及配置系统服务_删除nginx的系统服务

删除nginx的系统服务

一、安装nginx

1、安装所需的依赖

  1. # 安装gcc
  2. yum install gcc-c++
  3. # 安装PCRE pcre-devel
  4. yum install -y pcre pcre-devel
  5.  
  6. # 安装zlib
  7. yum install -y zlib zlib-devel
  8.  
  9. # 安装Open SSL
  10. yum install -y openssl openssl-devel

2、下载nginx稳定版

nginx官网下载
http://nginx.org/en/download.html
http://nginx.org/download/

  1. cd /home/
  2. # 下载
     
  3. wget http://nginx.org/download/nginx-1.23.2.tar.gz
  4. # tar zxvf 命令进行解压
  5. tar zxvf nginx-1.23.2.tar.gz
  6. # 重命名 nginx-1.23.2文件夹
  7. mv nginx-1.23.2 nginx

3、编译&安装

 # 进入nginx目录,默认安装目录:/usr/local/nginx(进入nginx文件夹,运行configure脚本)
cd /home/nginx/ 
# 执行命令 (默认会安装在/usr/local/nginx)这里通过configure命令指定安装目录
./configure --prefix=/webnginx
# 执行make命令(要是执行不成功请检查最开始安装的四个有没有安装成功)
# 执行make install命令
make && make install
# 查看编译参数命令
./configure --help | more

最后生成的文件夹具体如下

4、启动nginx

1.进入nginx下的sbin目录

cd /webnginx/sbin

2.执行启动

./nginx

3.查看nginx是否启动

ps -ef | grep nginx

4.浏览器访问你的IP

二、卸载nginx

1.查看nginx是否运行
ps aux | grep nginx

2.进入nginx下的sbin目录
cd /webnginx/sbin

3.停止nginx运行
./nginx -s stop

4.查看与Nginx有关的文件夹
find / -name nginx

5.删除与Nginx有关的文件
rm -rf file /webnginx*

6.再查看
find / -name nginx*

7.卸载Nginx的依赖
yum remove nginx
 

三、Nginx操作命令

1.进入nginx下的sbin目录

cd /webnginx/sbin

2.启动

./nginx

3.关闭 

./nginx -s stop

4.重启 

./nginx -s reload

四、配置成系统服务

 

  1. 1.创建nginx.service文件
  2. vim /usr/lib/systemd/system/nginx.service
  3. 2.nginx.service文件中写入内容
  4. [Unit]
  5. Description=nginx web service
  6. Documentation=http://nginx.org/en/docs/
  7. After=network.target
  8. [Service]
  9. Type=forking
  10. PIDFile=/webnginx/logs/nginx.pid
  11. ExecStartPre=/webnginx/sbin/nginx -t -c /webnginx/conf/nginx.conf
  12. ExecStart=/webnginx/sbin/nginx
  13. ExecReload=/webnginx/sbin/nginx -s reload
  14. ExecStop=/webnginx/sbin/nginx -s stop
  15. PrivateTmp=true
  16. [Install]
  17. WantedBy=default.target
  18. 3.改权限
  19. chmod 755 /usr/lib/systemd/system/nginx.service
  20. 4.文件生效
  21. systemctl daemon-reload
  22. 5.设置开机自启
  23. systemctl enable nginx.service

五、系统服务Nginx基本命令

  1. 1.启动
  2. systemctl start nginx
  3. 2.停止
  4. systemctl stop nginx
  5. 3.重启
  6. systemctl restart nginx
  7. 4.重新加载配置文件
  8. systemctl reload nginx
  9. 5. 查看Nginx状态
  10. systemctl status nginx
  11. 6.开机自动
  12. systemctl enable nginx

六、nginx.conf文件基本配置详解

  1. #user nobody;
  2. #进程的数量
  3. worker_processes 1;
  4. #错误日志:存放路径
  5. #error_log logs/error.log;
  6. #error_log logs/error.log notice;
  7. #error_log logs/error.log info;
  8. #进程标识符
  9. #pid logs/nginx.pid;
  10. events {
  11. worker_connections 1024;
  12. }
  13. #设定http服务器,利用它的反向代理功能提供负载均衡支持
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  18. # '$status $body_bytes_sent "$http_referer" '
  19. # '"$http_user_agent" "$http_x_forwarded_for"';
  20. #access_log logs/access.log main;
  21. sendfile on;
  22. #tcp_nopush on;
  23. #超时时间
  24. #keepalive_timeout 0;
  25. keepalive_timeout 65;
  26. #gzip on;
  27. #配置虚拟机
  28. server {
  29. listen 9990;#监听端口
  30. server_name localhost;#主机ip
  31. #请求转发
  32. location / {
  33. proxy_pass http://localhost:8001;
  34. }
  35. location /app{
  36. try_files $uri $uri/ /app/index.html;
  37. }
  38. #charset koi8-r;
  39. #access_log logs/host.access.log main;
  40. location / {
  41. root html;
  42. index index.html index.htm;
  43. }
  44. #error_page 404 /404.html;
  45. # redirect server error pages to the static page /50x.html
  46. #
  47. error_page 500 502 503 504 /50x.html;
  48. location = /50x.html {
  49. root html;
  50. }
  51. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  52. #
  53. #location ~ \.php$ {
  54. # proxy_pass http://127.0.0.1;
  55. #}
  56. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  57. #
  58. #location ~ \.php$ {
  59. # root html;
  60. # fastcgi_pass 127.0.0.1:9000;
  61. # fastcgi_index index.php;
  62. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  63. # include fastcgi_params;
  64. #}
  65. # deny access to .htaccess files, if Apache's document root
  66. # concurs with nginx's one
  67. #
  68. #location ~ /\.ht {
  69. # deny all;
  70. #}
  71. }
  72. # another virtual host using mix of IP-, name-, and port-based configuration
  73. #
  74. #server {
  75. # listen 8000;
  76. # listen somename:8080;
  77. # server_name somename alias another.alias;
  78. # location / {
  79. # root html;
  80. # index index.html index.htm;
  81. # }
  82. #}
  83. # HTTPS server
  84. #
  85. #server {
  86. # listen 443 ssl;
  87. # server_name localhost;
  88. # ssl_certificate cert.pem;
  89. # ssl_certificate_key cert.key;
  90. # ssl_session_cache shared:SSL:1m;
  91. # ssl_session_timeout 5m;
  92. # ssl_ciphers HIGH:!aNULL:!MD5;
  93. # ssl_prefer_server_ciphers on;
  94. # location / {
  95. # root html;
  96. # index index.html index.htm;
  97. # }
  98. #}
  99. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/553488
推荐阅读
相关标签
  

闽ICP备14008679号