nginx网站服务器 -ag凯发k8国际
ag凯发k8国际
收集整理的这篇文章主要介绍了
nginx网站服务器
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
文章目录
- nginx网站服务器
- nginx安装
- nginx启动与停止
- 启动nginx
- 关闭nginx
- 重启nginx
- nginx配置文件
nginx网站服务器
nginx安装
nginx web服务器软件安装完成后,程序主目录位于/usr/local/nginx/,该目录下的内容分别为
目录作用conf | 主配置文件目录 |
html | 网站根目录 |
logs | 日志文件目录 |
sbin | 主程序目录 |
nginx启动与停止
进入sbin目录下(以下操作,如无特殊说明,均在sbin目录下操作)
启动nginx
./nginx :启动nginx,这种方式nginx会自动读取conf目录下的nginx.conf的配置文件
./nginx -c 指定配置文件:用指定的配置文件启动nginx
./nginx -s reopen :重新打开日志文件
[root@localhost sbin]# ./nginx [root@localhost sbin]# ps -aux |grep nginx root 831 0.0 0.0 25516 1352 ? ss 14:50 0:00 nginx: master process ./nginx nobody 832 0.0 0.0 28032 2124 ? s 14:50 0:00 nginx: worker process root 834 0.0 0.0 112660 976 pts/2 s 14:51 0:00 grep --color=auto nginx一个主进程
关闭nginx
./nginx -s stop :快速停止nginx
./nginx -s quit :完整有序的停止nginx
其他停止nginx方式:
1.通过信号量强行关闭
[root@localhost nginx]# ps -aux | grep nginx root 831 0.0 0.0 25516 1352 ? ss 14:50 0:00 nginx: master process ./nginx nobody 832 0.0 0.0 28032 2368 ? s 14:50 0:00 nginx: worker process root 954 0.0 0.0 112660 976 pts/2 s 14:59 0:00 grep --color=auto nginx [root@localhost nginx]# kill -int 831 [root@localhost nginx]# ps -aux | grep nginx root 964 0.0 0.0 112660 972 pts/2 s 15:00 0:00 grep --color=auto nginx2.改变配置文件,平滑重读配置文件
[root@localhost nginx]# ps -aux|grep nginx root 985 0.0 0.0 25516 1984 ? ss 15:01 0:00 nginx: master process ./sbin/nginx nobody 1864 0.0 0.0 27600 2060 ? s 15:49 0:00 nginx: worker process root 2005 0.0 0.0 112664 976 pts/2 s 15:52 0:00 grep --color=auto nginx [root@localhost nginx]# kill -hup 985重启nginx
./nginx -s reload : 重启,一般修改配置后重新加载生效
nginx配置文件
nginx默认配置文件为/usr/local/nginx/conf/nginx.conf,配置文件主要包括全局,event,http,server设置。event主要用来定义nginx工作模式;http提供web功能;server用来设置虚拟主机,且server必须位于http内部,一个配置文件中可以有多个server
... #全局块events { #events块... }http #http块 {... #http全局块server #server块{ ... #server全局块location [pattern] #location块{...}location [pattern] {...}}server{...}... #http全局块 } #user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; }http {include 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"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the php scripts to apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the php scripts to fastcgi server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param script_filename /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of ip-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# https server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:ssl:1m;# ssl_session_timeout 5m;# ssl_ciphers high:!anull:!md5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#} } //设置用户与组,一般用#注释掉 user nobody; //启动子进程数,可以通过ps aux | grep nginx 查看 worker_processes 1; //错误日志文件,以及日志级别 error_log logs/error.log info; //进程号保存的文件 pid logs/nginx.pid;//主要用来定义nginx工作模式 events {//每个进程可以处理的链接数,受系统文件句柄的限制worker_connections 1024; }//提供web功能 http {//mime.types为文件类型定义文件include mime.types;default_type application/octet-stream;sendfile on;tcp_nopush on;keepalive_timeout 65;gzip on;//使用server定义虚拟主机server {listen 80;server_name www.baidu.com;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}//消费者查询系统中间件 、 全程版系统中间件location ~ /api/1.0/ll/(.*) {proxy_pass http://59.68.29.89:18081/api/1.0/ll/$1;proxy_set_header host $host:80;proxy_set_header x-real-ip $remote_addr;proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;}}}总结
以上是ag凯发k8国际为你收集整理的nginx网站服务器的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: