Nginx服务器是192.168.2.80
安装nginx服务
[[email protected] ~] # yum -y install nginx
编辑nginx主配置文件
[[email protected] ~] # vim /etc/nginx/nginx.conf
1 # For more information on configuration, see:
2 # * Official English Documentation: http://nginx.org/en/docs/
3 # * Official Russian Documentation: http://nginx.org/ru/docs/
4
5 user nginx;
6 worker_processes 1;
7
8 error_log /var/log/nginx/error .log;
9 #error_log /var/log/nginx/error.log notice;
10 #error_log /var/log/nginx/error.log info;
11
12 pid /var/run/nginx .pid;
13
14
15 events {
16 worker_connections 1024;
17 }
18
19
20 http {
21 include /etc/nginx/mime .types;
22 default_type application /octet-stream ;
23
24 log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
25 ‘$status $body_bytes_sent "$http_referer" ‘
26 ‘"$http_user_agent" "$http_x_forwarded_for"‘ ;
27
28 access_log /var/log/nginx/access .log main;
29
30 sendfile on;
31 #tcp_nopush on;
32
33 #keepalive_timeout 0;
34 keepalive_timeout 65;
35
36 #gzip on;
37
38 # Load config files from the /etc/nginx/conf.d directory
39 # The default server is in conf.d/default.conf
40 include /etc/nginx/conf .d/*.conf;
41
42 }
在此配置文件的40行出有include,后边跟的文件就是主配置文件的关联文件。因此我们编辑关联文件配置虚拟主机。
[[email protected] ~] # vim /etc/nginx/conf.d/default.conf
4 server {
5 listen 80 default_server;
6 server_name _;
7
8 #charset koi8-r;
9
10 #access_log logs/host.access.log main;
11
12 # Load configuration files for the default server block.
13 include /etc/nginx/default .d/*.conf;
14
15 location / {
16 root /usr/share/nginx/html ;
17 index index.html index.htm;
18 if ( $request_uri ~* \.html$ ){
19 proxy_pass http: //192 .168.2.80;
20 }
21 if ( $request_uri ~* \.php$ ){
22 proxy_pass http: //192 .168.2.93;
23 }
24 }
25
26 error_page 404 /404 .html;
27 location = /404 .html {
28 root /usr/share/nginx/html ;
29 }
30
31 # redirect server error pages to the static page /50x.html
32 #
33 error_page 500 502 503 504 /50x .html;
34 location = /50x .html {
35 root /usr/share/nginx/html ;
36 }
60 }
在这个配置文件中我们主要修改的是监听的端口,还有location中的跳转服务地址(分辨请求的是动态页面还是静态页面,实现动静分离)。
配置完成后我们启动nginx服务
[[email protected] ~] # service nginx start
|