本来想要实现这种效果
nginx.conf配置文件如下
[root@localhost conf]# vi nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/conf.d/*.conf;
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;
client_header_buffer_size 100M;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8088;
server_name localhost;
root /home/files/;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { expires 15d; }
location ~ .*\.(gif|jpg|pocx|poc|xls|xlsx|mp4|jpeg|png)$ {
expires 24h;
root /home/files/;
access_log /home/nginx/logs/images.log;
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /home/files/;
proxy_redirect off;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1:8088;
}
}
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
哥们,你这个配置的有问题啊,这个是占用了8088端口
server {
listen 8088;
}
下面的配置,也就是
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1:8088;
}
也是8088端口,你是要弄甚
/home/files/html
这个目录存在吗,有什么文件,你root映射的路径正确吗
vim /usr/local/nginx/conf/nginx.conf
1 user www www; #nginx 系统用户和用户组(了解)
2
3 worker_processes auto;#启动进程
4
5 error_log /home/wwwlogs/nginx_error.log crit;#错误日志
6
7 pid /usr/local/nginx/logs/nginx.pid;
8#主程序pid保存文件
9 #Specifies the value for maximum file descriptors that can be opened by this process.
10 worker_rlimit_nofile 51200;
11#文件描述符数量
12 events
13 {
14 use epoll;#linux建议使用epoll
15 worker_connections 51200;
#单个工作进程最大允许连接数
16 multi_accept on;
17 }
18#http 整个环境配置
19 http
20 {
21 include mime.types;
22 default_type application/octet-stream;
23 #设定mime类型 文件传送类型有mimetype文件定义
24 server_names_hash_bucket_size 128;
25 client_header_buffer_size 32k;
26 large_client_header_buffers 4 32k;
27 client_max_body_size 50m;
28 #serndfile on 是必须设置为on
29 sendfile on;
30 tcp_nopush on;
31
32 keepalive_timeout 60;
33 #连接超时时间
34 tcp_nodelay on;
#禁用naglo算法 也就是不缓存数据
35
36 fastcgi_connect_timeout 300;
37 fastcgi_send_timeout 300;
38 fastcgi_read_timeout 300;
39 fastcgi_buffer_size 64k;
40 fastcgi_buffers 4 64k;
41 fastcgi_busy_buffers_size 128k;
42 fastcgi_temp_file_write_size 256k;
43
44 gzip on;
45 gzip_min_length 1k;
46 gzip_buffers 4 16k;
47 gzip_http_version 1.1;
48 gzip_comp_level 2;
49 gzip_types text/plain application/javascript application/x-javas cript text/javascript text/css application/xml application/xml+rss;
50 gzip_vary on;
51 gzip_proxied expired no-cache no-store private auth;
52 gzip_disable "MSIE [1-6].";
53 #网络压缩
54 #limit_conn_zone $binary_remote_addr zone=perip:10m;
55 ##If enable limit_conn_zone,add "limit_conn perip 10;" to server sec tion.
56
57 server_tokens off;
#隐藏nginx 版本号
58 #log format
59 log_format access '$remote_addr - $remote_user [$time_local] "$req uest" '
60 '$status $body_bytes_sent "$http_referer" '
61 '"$http_user_agent" $http_x_forwarded_for';
62 # 定义日志格式
access_log off;
63
64 server
65 {
66 listen 80 default_server;#监听80端口
67 #listen [::]:80 default_server ipv6only=on;
68 server_name www.lnmp.org;#服务器名
69 index index.html index.htm index.php; #默认网站页面
70 root /home/wwwroot/default; #网页主目录
71
72 #error_page 404 /404.html;
73 include enable-php.conf;
74
75 location /nginx_status
76 {
77 stub_status on;
78 access_log off;
79 }
80 #开启status 状态监听
81 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
82 {
83 expires 30d;
84 }
85 静态文件处理保存时间 30天
86 location ~ .*.(js|css)?$
87 {
expires 12h;
89 }
js和css文件处理保存时间12小时
90
91 location ~ /.
92 {
93 deny all;
94 }
95 #正确访问日志
96 access_log /home/wwwlogs/access.log access;
97 }# vhost 下面是子配置文件生效
98 include vhost/*.conf;
99 }
100
八、检查nginx 配置文件语法错误
/usr/local/ngind/sbin/nginx -t
九、nginx 虚拟主机(重点重点重点)
www.sina.com 跳转到我们指定的页面上
1. 没有目录 创建目录
mkdir /home/wwwroot/sina/
mkdir /home/wwwroot/sohu/
2. 文件夹里面没有测试文件
vim /home/wwwroot/sina/index.html
vim /home/wwwroot/sohu/index.html
3. 调整我们的配置文件 www.sina.com->/home/wwwroot/sina/index.html
vim /usr/local/nginx/conf/nginx.conf
server
{
#listen 80 default_server;
listen 80;
#listen [::]:80 default_server ipv6only=on;
#server_name www.lnmp.org;
server_name www.sina.com
index index.html index.htm index.php;
#root /home/wwwroot/default;
root /home/wwwroot/sina;
#error_page 404 /404.html;
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
#access_log /home/wwwlogs/access.log access;
access_log /home/wwwlogs/access_sina.log access;
}
include vhost/*.conf;
}
检测配置文件是否修改成功
/usr/local/nginx/sbin/nginx -t
出现下面内容说明配置文件没有任何问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重启nginx
lnmp restart
十、列表页显示(重点重点重点)
1. 修改配置文件
vim /usr/local/nginx/conf/nginx.conf
server
{
#listen 80 default_server;
listen 80;
#listen [::]:80 default_server ipv6only=on;
#server_name www.lnmp.org;
server_name www.sina.com
index index.html index.htm index.php;
#root /home/wwwroot/default;
root /home/wwwroot/sina;
autoindex on;
#error_page 404 /404.html;
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires
[root@localhost sbin]# vim /usr/local/nginx/conf/nginx.conf
user root;
#user www www;
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /usr/local/nginx/logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
#access_log logs/access.log main;
client_header_buffer_size 100M;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#gzip on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 8080 default_server;
server_name _;
index index.html index.htm index.php;
root /home/files/;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { expires 15d; }
location ~ .*\.(gif|jpg|pocx|poc|xls|xlsx|mp4|jpeg|png)$ {
expires 24h;
root /home/files/;
access_log /home/nginx/logs/images.log;
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /home/files/;
proxy_redirect off;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1:8088;
}
}
location / {
root /e:/HRoneFileServer;
proxy_pass http://127.0.0.1:88;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_intercept_errors on;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
charset utf-8,gbk;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}