nginx 环境配置,nginx配置


1.yum install nginx -y //在 CentOS 上,可直接使用 yum 来安装 Nginx
2.nginx //安装完成后,使用 nginx 命令启动 Nginx:此时,访问 http://119.29.235.194 可以看到 Nginx 的测试页面

3.打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的 root /usr/share/nginx/html; 修改为: root /data/www;,如下:

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 ‘remoteaddrremote_user [timelocal]"request” ’
statusbody_bytes_sent “httprefererhttp_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 {
    }
}

}

(配置文件将 /data/www/static 作为所有静态资源请求的根路径,如访问: http://119.29.235.194/static/index.js,将会去 /data/www/static/ 目录下去查找 index.js。现在我们需要重启 Nginx 让新的配置生效,如:)
4.nginx -s reload
(重启后,现在我们应该已经可以使用我们的静态服务器了,现在让我们新建一个静态文件,查看服务是否运行正常。)

5.首先让我们在 /data 目录 下创建 www 目录,如:
mkdir -p /data/www
创建第一个静态文件
在 /data/www 目录下创建我们的第一个静态文件 index.html

转载请注明出处

相关内容

    暂无相关文章