上一节记录了nginx的安装,这里来试着修改下配置文件。
1#user nobody; 2worker_processes 1; 3 4#error_log logs/error.log; 5#error_log logs/error.log notice; 6#error_log logs/error.log info; 7 8#pid logs/nginx.pid; 9 10 11events { 12 worker_connections 1024; 13} 14 15 16http { 17 include mime.types; 18 default_type application/octet-stream; 19 20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 21 # '$status $body_bytes_sent "$http_referer" ' 22 # '"$http_user_agent" "$http_x_forwarded_for"'; 23 24 #access_log logs/access.log main; 25 26 sendfile on; 27 #tcp_nopush on; 28 29 #keepalive_timeout 0; 30 keepalive_timeout 65; 31 32 #gzip on; 33 34 server { 35 listen 80; 36 server_name localhost; 37 root /data/wwwroot1; 38 charset utf-8; 39 #access_log logs/host.access.log main; 40 # / 所有做负债均衡 + 反向代理 41 location / { 42 root /data/wwwroot1; 43 index index.html index.htm; 44 } 45 46 error_page 404 /404.html; 47 48 # redirect server error pages to the static page /50x.html 49 # 50 error_page 500 502 503 504 /50x.html; 51 location = /50x.html { 52 root html; 53 } 54 55 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 56 # 57 #location ~ \.php$ { 58 # proxy_pass http://127.0.0.1; 59 #} 60 61 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 62 # 63 #location ~ \.php$ { 64 # root html; 65 # fastcgi_pass 127.0.0.1:9000; 66 # fastcgi_index index.php; 67 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 68 # include fastcgi_params; 69 #} 70 71 # deny access to .htaccess files, if Apache's document root 72 # concurs with nginx's one 73 # 74 #location ~ /\.ht { 75 # deny all; 76 #} 77 } 78 79 80 # another virtual host using mix of IP-, name-, and port-based configuration 81 # 82 #server { 83 # listen 8000; 84 # listen somename:8080; 85 # server_name somename alias another.alias; 86 87 # location / { 88 # root html; 89 # index index.html index.htm; 90 # } 91 #} 92 93 94 # HTTPS server 95 # 96 #server { 97 # listen 443 ssl; 98 # server_name localhost; 99 100 # ssl_certificate cert.pem; 101 # ssl_certificate_key cert.key; 102 103 # ssl_session_cache shared:SSL:1m; 104 # ssl_session_timeout 5m; 105 106 # ssl_ciphers HIGH:!aNULL:!MD5; 107 # ssl_prefer_server_ciphers on; 108 109 # location / { 110 # root html; 111 # index index.html index.htm; 112 # } 113 #} 114 115}
注意 这行代码,将访问目录由默认的html目录指向了,root 下面配置的目录,
root /data/wwwroot1;
修改完成后软重启
[root@VM_0_4_centos ~]# kill -HUP 28041
也可以使用
1#检测配置文件是否合法 2/usr/local/nginx/sbin/nginx -t
重启:
/usr/local/nginx/sbin/nginx -s reload
这样,文件放置到 /data/wwwroot1 目录下,就能够访问到了。