目录
之前的代码都是通过node xxxx.js
来运行,一旦关闭了命令行窗口,程序就终止了;
现在将观察怎么样才可以让程序在关闭命令行窗口后仍然运行。
sudo npm install -g forever
forever start xxx.js
//当想要关闭时
forever stop index.js
发现了一些新问题,所以在展开网站的内容之前,添加一些常识性的笔记
发现了好玩的nginx 有了nginx之后,forever start xxx.js 就没用了
1 mysqladmin -uroot -p123456 password 123
OR
2 set password for root@localhost = password('Yannian002.');
mysql -u root -p
[emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)问题
当出现这个错误时,意味着80端口被占用。
方法:
fuser -k 80/tcp
将进程杀死后,启动nginx。
systemctl enable nginx.service
外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的 root/usr/share/nginx/html; 修改为: /root/Nicolas_Web; 如下:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
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;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /data/www;
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
阅读之后发现:
/usr/share/nginx/html
这个是ngix安装好只会放主页的默认路径
打开这个html文件之后看到的是:
[root@10-255-20-136 html]# ls
404.html 50x.html en-US icons img index.html nginx-logo.png poweredby.png
是储存nginx网站的文件夹
根据上述文件,我们可以很明显的将 nginx.conf 配置文件分为三部分:
全局块
从配置文件开始到 events 块之间的内容,主要会设置一些影响nginx 服务器整体运行的配置指令,主要包括配置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等。
events块
events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括是否开启对多 work process 下的网络连接进行序列化,是否允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 word process 可以同时支持的最大连接数等。
上述例子就表示每个 work process 支持的最大连接数为 1024.
这部分的配置对 Nginx 的性能影响较大,在实际中应该灵活配置。
http块
最重要的部分:
这算是 Nginx 服务器配置中最频繁的部分,代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。
需要注意的是:http 块也可以包括 http全局块、server 块。
很详细的解释:
https://blog.csdn.net/weixin_40792878/article/details/83117755#2.events%E5%9D%97%E6%8C%87%E4%BB%A4%E9%85%8D%E7%BD%AE
目前只记录最关注的一部分内容:Server块指令配置:
设置网站的默认首页
指令index用来设置网站默认首页、一般有两个作用:
一是:用户在发出请求网站时,请求地址可以不写首页名称
二是:可以对一个请求,根据请求内容而设置不同的首页
语法结构:index? file ...? ; file变量可以包含多个文件,中间用空格隔开也可以包含其他变量,默认使用 "index.html";
例子:location ~ ^ /data/(.+)/web/${
? ? index index.$1.html??index.m1.html?index.html?}? //当location匹配到“/data/locationtest/web” 时,匹配成功,$1的值就为“locationtest”,那么就会依次寻找这个页面下的 index.locationtest.html???index.m1.html?index.html? ,先找到那个就返回那个。
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
在con.f文件夹下的default文件内看到
upstream tomcat {
server 127.0.0.1:8080;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
server_name localhost;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
proxy_pass http://tomcat;
}
}
/var/log/nginx/error.log目录下查看错误日志
解决Nginx出现403 forbidden (13: Permission denied)报错的四种方法
一、由于启动用户和nginx工作用户不一致所致
1.1查看nginx的启动用户,发现是nobody,而为是用root启动的
命令:ps aux | grep "nginx: worker process" | awk‘{print $1}‘
1.2将nginx.config的user改为和启动用户一致,
命令:vi conf/nginx.conf
二、缺少index.html或者index.php文件,就是配置文件中index index.html index.htm这行中的指定的文件。
server {
listen 80;
server_name localhost;
index index.php index.html;
root /data/www/;
}
如果在/data/www/下面没有index.php,index.html的时候,直接文件,会报403 forbidden。
原文:https://www.cnblogs.com/samanian/p/12181236.html