vi /usr/local/nginx/conf/nginx.conf
新手请记得备份一下再操作。
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;
# 404 500
fastcgi_intercept_errors on;
...
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# 假如服务器ip是192.168.10.125,则访问 192.168.10.125 实际访问的目录是:/usr/local/nginx/html/index.html
location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:3000;
}
# 配置 404 状态页面指向,指向的是:root 中的 html 的绝对路径是 /usr/local/nginx/html/404.html 文件
error_page 404 /404.html;
location = /404.html {
root html;
}
...
error_page 500 /500.html;
location = /500.html {
root html;
}
error_page 502 /502.html;
location = /502.html {
root html;
}
...
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
访问服务器ip时,失败,通过tail -n 5 /usr/local/nginx/logs/error.log
查看nginx错误日志发现:
2019/01/29 16:01:10 [error] 4351#0: *21 connect() failed (111: Connection refused) while connecting to ups
tream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3
000/", host: "xxx.xxx.xxx.xxx:80"
原因可能是:
新买的阿里云服务器 就属于这种情况,有nginx,但是没安装php-fpm 这种情况下可参考 centos安装php php-fpm 以及 配置nginx
在server段里加字符集配置:
default_type 'text/html';
charset utf-8;
检查: /usr/local/nginx/sbin/nginx -t
重启: /usr/local/nginx/sbin/nginx -s reload