nginx 启动(任意目录下):/p>

nginx

NGINX 停止(任意目录下)/p>

nginx -s stop
nginx 配置文件:
cd /etc/nginx
cat nginx.conf
#user www-data;
worker_processes 2;
pid /run/nginx.pid;
events {
  worker_connections 768;
}
http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  server_names_hash_max_size 1024;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
使用了gzip
  gzip on;
  gzip_disable "msie6";
nbsp; gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled#
cat linlin.fun
server {
  listen       80;
  server_name  linlin.fun www.linlin.fun;
  charset utf-8;
  location ~ ^/uploads/ {
    root /root/blog/public;
  }
  location / {
    #root localhost:3000;
    proxy_pass          http://linlin_fun_server;
    #proxy_redirect      default;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    Host $http_host;
    proxy_next_upstream http_502 http_504 error timeout invalid_header;
  }
  location ~ ^/assets/ {
    root /root/blog/public;
    #expires 1y;
    #add_header Cache-Control public;
    #add_header ETag "";
    break;
  }
}
upstream linlin_fun_server{
  server localhost:3000;
}

然后在sites-enabled/文件夹内创建子文件,可以使用域名进行命名:

cd /etc/nginx/sites-enabled#
cat linlin.fun
server {
  listen       80;
  server_name  linlin.fun www.linlin.fun;
  charset utf-8;
  location ~ ^/uploads/ {
    root /root/blog/public;
  }
  location / {
    #root localhost:3000;
    proxy_pass          http://linlin_fun_server;
    #proxy_redirect      default;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    Host $http_host;
    proxy_next_upstream http_502 http_504 error timeout invalid_header;
  }
  location ~ ^/assets/ {
    root /root/blog/public;
    #expires 1y;
    #add_header Cache-Control public;
    #add_header ETag "";
    break;
  }
}
upstream linlin_fun_server{
  server localhost:3000;
}

子域名也使用域名进行命名

 cat hi.linlin.fun
server {
  listen 80;
  server_name hi.linlin.fun www.hi.linlin.fun;
  location / {
    root /opt/app/hi.linlin.fun;
#    index index.html index.htm;
  }
  location /test/ {
    root /opt/app/hi.linlin.fun/test.html;
    autoindex on;
  }
}
/var/log#
/var/log/nginx#
tail -f error.log access.log

nginx log的使用:

进入/var/log/nginx# 目录下

cd /var/log/nginx#

同时查看成功和报错的日志:

tail -f access.log error.log