CentOS 7下Nginx服务器的安装以及配置

CentOS 7下Nginx服务器的安装以及配置

一、配置epel yum 源

1、我们进入自己新建的一个目录。

[root@VM_0_3_centos tools]# pwd
/usr/local/tools

2、配置epel yum 源

[root@VM_0_3_centos tools]# wget http://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
--2018-03-14 09:23:19--  http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Resolving dl.fedoraproject.org (dl.fedoraproject.org)... 209.132.181.25, 209.132.181.23, 209.132.181.24
Connecting to dl.fedoraproject.org (dl.fedoraproject.org)|209.132.181.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15080 (15K) [application/x-rpm]
Saving to: ‘epel-release-latest-7.noarch.rpm’

100%[=====================================================================================================================================================>] 15,080      89.4KB/s   in 0.2s   

2018-03-14 09:23:20 (89.4 KB/s) - ‘epel-release-latest-7.noarch.rpm’ saved [15080/15080]

[root@VM_0_3_centos tools]# rpm -ivh epel-release-latest-7.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-7-11                ################################# [100%]

3、安装nginx

[root@VM_0_3_centos tools]# yum install nginx -y
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
mysql-connectors-community                                                                                                                                              | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                                   | 2.5 kB  00:00:00     
mysql56-community                                                                                                                                                       | 2.5 kB  00:00:00     
os                                                                                                                                                                      | 3.6 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.12.2-1.el7 will be installed
--> Processing Dependency: nginx-all-modules = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: nginx-filesystem = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-1.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 0:2.4-8.el7 will be installed
--> Processing Dependency: libunwind.so.8()(64bit) for package: gperftools-libs-2.4-8.el7.x86_64
---> Package nginx-all-modules.noarch 1:1.12.2-1.el7 will be installed
--> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-mail = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-stream = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
---> Package nginx-filesystem.noarch 1:1.12.2-1.el7 will be installed
--> Running transaction check
---> Package libunwind.x86_64 2:1.2-2.el7 will be installed
---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 will be installed
---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 will be installed
--> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
--> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
---> Package nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 will be installed
---> Package nginx-mod-mail.x86_64 1:1.12.2-1.el7 will be installed
---> Package nginx-mod-stream.x86_64 1:1.12.2-1.el7 will be installed
--> Running transaction check
---> Package gd.x86_64 0:2.0.35-26.el7 will be installed
--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Running transaction check
---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                                     Arch                                   Version                                         Repository                            Size
===============================================================================================================================================================================================
Installing:
 nginx                                                       x86_64                                 1:1.12.2-1.el7                                  epel                                 529 k
Installing for dependencies:
 gd                                                          x86_64                                 2.0.35-26.el7                                   os                                   146 k
 gperftools-libs                                             x86_64                                 2.4-8.el7                                       os                                   272 k
 libXpm                                                      x86_64                                 3.5.12-1.el7                                    os                                    55 k
 libunwind                                                   x86_64                                 2:1.2-2.el7                                     os                                    57 k
 nginx-all-modules                                           noarch                                 1:1.12.2-1.el7                                  epel                                  16 k
 nginx-filesystem                                            noarch                                 1:1.12.2-1.el7                                  epel                                  17 k
 nginx-mod-http-geoip                                        x86_64                                 1:1.12.2-1.el7                                  epel                                  23 k
 nginx-mod-http-image-filter                                 x86_64                                 1:1.12.2-1.el7                                  epel                                  26 k
 nginx-mod-http-perl                                         x86_64                                 1:1.12.2-1.el7                                  epel                                  35 k
 nginx-mod-http-xslt-filter                                  x86_64                                 1:1.12.2-1.el7                                  epel                                  25 k
 nginx-mod-mail                                              x86_64                                 1:1.12.2-1.el7                                  epel                                  53 k
 nginx-mod-stream                                            x86_64                                 1:1.12.2-1.el7                                  epel                                  76 k

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package (+12 Dependent packages)

Total download size: 1.3 M
Installed size: 4.0 M
Downloading packages:
(1/13): gd-2.0.35-26.el7.x86_64.rpm                                                                                                                                     | 146 kB  00:00:00     
(2/13): gperftools-libs-2.4-8.el7.x86_64.rpm                                                                                                                            | 272 kB  00:00:00     
(3/13): libunwind-1.2-2.el7.x86_64.rpm                                                                                                                                  |  57 kB  00:00:00     
(4/13): libXpm-3.5.12-1.el7.x86_64.rpm                                                                                                                                  |  55 kB  00:00:00     
(5/13): nginx-all-modules-1.12.2-1.el7.noarch.rpm                                                                                                                       |  16 kB  00:00:00     
(6/13): nginx-filesystem-1.12.2-1.el7.noarch.rpm                                                                                                                        |  17 kB  00:00:00     
(7/13): nginx-1.12.2-1.el7.x86_64.rpm                                                                                                                                   | 529 kB  00:00:00     
(8/13): nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm                                                                                                             |  26 kB  00:00:00     
(9/13): nginx-mod-http-geoip-1.12.2-1.el7.x86_64.rpm                                                                                                                    |  23 kB  00:00:00     
(10/13): nginx-mod-http-perl-1.12.2-1.el7.x86_64.rpm                                                                                                                    |  35 kB  00:00:00     
(11/13): nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64.rpm                                                                                                             |  25 kB  00:00:00     
(12/13): nginx-mod-mail-1.12.2-1.el7.x86_64.rpm                                                                                                                         |  53 kB  00:00:00     
(13/13): nginx-mod-stream-1.12.2-1.el7.x86_64.rpm                                                                                                                       |  76 kB  00:00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                          2.5 MB/s | 1.3 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : 2:libunwind-1.2-2.el7.x86_64                                                                                                                                               1/13 
  Installing : gperftools-libs-2.4-8.el7.x86_64                                                                                                                                           2/13 
  Installing : 1:nginx-filesystem-1.12.2-1.el7.noarch                                                                                                                                     3/13 
  Installing : libXpm-3.5.12-1.el7.x86_64                                                                                                                                                 4/13 
  Installing : gd-2.0.35-26.el7.x86_64                                                                                                                                                    5/13 
  Installing : 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64                                                                                                                                 6/13 
  Installing : 1:nginx-mod-http-perl-1.12.2-1.el7.x86_64                                                                                                                                  7/13 
  Installing : 1:nginx-mod-stream-1.12.2-1.el7.x86_64                                                                                                                                     8/13 
  Installing : 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64                                                                                                                           9/13 
  Installing : 1:nginx-mod-mail-1.12.2-1.el7.x86_64                                                                                                                                      10/13 
  Installing : 1:nginx-1.12.2-1.el7.x86_64                                                                                                                                               11/13 
  Installing : 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64                                                                                                                         12/13 
  Installing : 1:nginx-all-modules-1.12.2-1.el7.noarch                                                                                                                                   13/13 
  Verifying  : libXpm-3.5.12-1.el7.x86_64                                                                                                                                                 1/13 
  Verifying  : 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64                                                                                                                                 2/13 
  Verifying  : 1:nginx-mod-http-perl-1.12.2-1.el7.x86_64                                                                                                                                  3/13 
  Verifying  : gperftools-libs-2.4-8.el7.x86_64                                                                                                                                           4/13 
  Verifying  : 1:nginx-filesystem-1.12.2-1.el7.noarch                                                                                                                                     5/13 
  Verifying  : 1:nginx-mod-stream-1.12.2-1.el7.x86_64                                                                                                                                     6/13 
  Verifying  : gd-2.0.35-26.el7.x86_64                                                                                                                                                    7/13 
  Verifying  : 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64                                                                                                                          8/13 
  Verifying  : 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64                                                                                                                           9/13 
  Verifying  : 2:libunwind-1.2-2.el7.x86_64                                                                                                                                              10/13 
  Verifying  : 1:nginx-all-modules-1.12.2-1.el7.noarch                                                                                                                                   11/13 
  Verifying  : 1:nginx-mod-mail-1.12.2-1.el7.x86_64                                                                                                                                      12/13 
  Verifying  : 1:nginx-1.12.2-1.el7.x86_64                                                                                                                                               13/13 

Installed:
  nginx.x86_64 1:1.12.2-1.el7                                                                                                                                                                  

Dependency Installed:
  gd.x86_64 0:2.0.35-26.el7                  gperftools-libs.x86_64 0:2.4-8.el7                libXpm.x86_64 0:3.5.12-1.el7                libunwind.x86_64 2:1.2-2.el7                      
  nginx-all-modules.noarch 1:1.12.2-1.el7    nginx-filesystem.noarch 1:1.12.2-1.el7            nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7  nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 
  nginx-mod-http-perl.x86_64 1:1.12.2-1.el7  nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7  nginx-mod-mail.x86_64 1:1.12.2-1.el7        nginx-mod-stream.x86_64 1:1.12.2-1.el7            

Complete!

二、查看确认 是否安装,并查看安装后所生成的文件

[root@VM_0_3_centos tools]# rpm -qa | grep nginx
nginx-mod-stream-1.12.2-1.el7.x86_64
nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
nginx-filesystem-1.12.2-1.el7.noarch
nginx-mod-http-perl-1.12.2-1.el7.x86_64
nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
nginx-1.12.2-1.el7.x86_64
nginx-all-modules-1.12.2-1.el7.noarch
nginx-mod-http-geoip-1.12.2-1.el7.x86_64
nginx-mod-mail-1.12.2-1.el7.x86_64
[root@VM_0_3_centos tools]#  rpm -ql nginx 
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/etc/nginx/scgi_params
/etc/nginx/scgi_params.default
/etc/nginx/uwsgi_params
/etc/nginx/uwsgi_params.default
/etc/nginx/win-utf
/usr/bin/nginx-upgrade
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx/modules
/usr/sbin/nginx
/usr/share/doc/nginx-1.12.2
/usr/share/doc/nginx-1.12.2/CHANGES
/usr/share/doc/nginx-1.12.2/README
/usr/share/doc/nginx-1.12.2/README.dynamic
/usr/share/doc/nginx-1.12.2/UPGRADE-NOTES-1.6-to-1.10
/usr/share/licenses/nginx-1.12.2
/usr/share/licenses/nginx-1.12.2/LICENSE
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx-upgrade.8.gz
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx/html/404.html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/usr/share/nginx/html/nginx-logo.png
/usr/share/nginx/html/poweredby.png
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/indent/nginx.vim
/usr/share/vim/vimfiles/syntax/nginx.vim
/var/lib/nginx
/var/lib/nginx/tmp
/var/log/nginx

三、测试Nginx

1.启动nginx

[root@VM_0_3_centos tools]# systemctl start nginx

2.设置开机启动

[root@VM_0_3_centos tools]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

3.查看nginx启动状态

[root@VM_0_3_centos tools]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-03-14 09:51:00 CST; 2min 32s ago
 Main PID: 13899 (nginx)
   CGroup: /system.slice/nginx.service
           ├─13899 nginx: master process /usr/sbin/nginx
           └─13900 nginx: worker process

Mar 14 09:51:00 VM_0_3_centos systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 14 09:51:00 VM_0_3_centos nginx[13894]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 14 09:51:00 VM_0_3_centos nginx[13894]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 14 09:51:00 VM_0_3_centos systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Mar 14 09:51:00 VM_0_3_centos systemd[1]: Started The nginx HTTP and reverse proxy server.

4.查看是否监听

[root@VM_0_3_centos tools]# ss -tnl | grep 80
LISTEN     0      128          *:80                       *:*                  
LISTEN     0      100          *:8080                     *:*                  
LISTEN     0      1      127.0.0.1:8005                     *:*                  
LISTEN     0      100          *:8009                     *:*                  
LISTEN     0      128         :::80                      :::*                  
LISTEN     0      80          :::3306                    :::*       

或者

[root@VM_0_3_centos tools]# netstat -apnt | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13899/nginx: master 
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      22511/java          
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      22511/java          
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      22511/java          
tcp        0      0 172.16.0.3:22           222.186.52.123:57280    ESTABLISHED 14257/sshd: root [p 
tcp6       0      0 :::80                   :::*                    LISTEN      13899/nginx: master 

5.测试

在浏览器中输入 nginx 服务器的ip 地址 
备注:如果不能正常访问,关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)


表示安装成功

四、Nginx的配置文件说明

配置文件路径,已经查看配置文件

[root@VM_0_3_centos tools]# cd /etc/nginx
[root@VM_0_3_centos nginx]# pwd
/etc/nginx
[root@VM_0_3_centos nginx]# ll
total 68
drwxr-xr-x 2 root root 4096 Oct 18 16:12 conf.d
drwxr-xr-x 2 root root 4096 Oct 18 16:12 default.d
-rw-r--r-- 1 root root 1077 Oct 18 16:09 fastcgi.conf
-rw-r--r-- 1 root root 1077 Oct 18 16:09 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 Oct 18 16:09 fastcgi_params
-rw-r--r-- 1 root root 1007 Oct 18 16:09 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Oct 18 16:09 koi-utf
-rw-r--r-- 1 root root 2223 Oct 18 16:09 koi-win
-rw-r--r-- 1 root root 3957 Oct 18 16:09 mime.types
-rw-r--r-- 1 root root 3957 Oct 18 16:09 mime.types.default
-rw-r--r-- 1 root root 2467 Oct 18 16:09 nginx.conf
-rw-r--r-- 1 root root 2656 Oct 18 16:09 nginx.conf.default
-rw-r--r-- 1 root root  636 Oct 18 16:09 scgi_params
-rw-r--r-- 1 root root  636 Oct 18 16:09 scgi_params.default
-rw-r--r-- 1 root root  664 Oct 18 16:09 uwsgi_params
-rw-r--r-- 1 root root  664 Oct 18 16:09 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Oct 18 16:09 win-utf
[root@VM_0_3_centos nginx]# cat nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /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;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        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 {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        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 {
#        }
#    }

}

添加注解后的配置文件

#运行用户
user nginx;
#启动进程,通常设置成和 cpu 的数量相等
worker_processes 1;
#全局错误日志及 PID 文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#工作模式及连接数上限
events {
#epoll 是多路复用 IO(I/O Multiplexing)中的一种方式,
#仅用于 linux2.6 以上内核,可以大大提高 nginx 的性能
use epoll;
#单个后台 worker process 进程的最大并发链接数
worker_connections 1024;
# 并发总数是 worker_processes 和 worker_connections 的乘积
# 即 max_clients = worker_processes * worker_connections
# 在设置了反向代理的情况下, max_clients = worker_processes * worker_connections / 4

为什么
# 为什么上面反向代理要除以 4,应该说是一个经验值
# 根据以上条件,正常情况下的 Nginx Server 可以应付的最大连接数为: 4 * 8000 = 32000
# worker_connections 值的设置跟物理内存大小有关
# 因为并发受 IO 约束, max_clients 的值须小于系统可以打开的最大文件数
# 而系统可以打开的最大文件数和内存大小成正比,一般 1GB 内存的机器上可以打开的文件数大约是
10 万左右
# 我们来看看 360M 内存的 VPS 可以打开的文件句柄数是多少:
# $ cat /proc/sys/fs/file-max
# 输出 34336
# 32000 < 34336,即并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受
的范围之内
# 所以, worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文
件总数进行适当地进行设置
# 使得并发总数小于操作系统可以打开的最大文件数目
# 其实质也就是根据主机的物理 CPU 和内存进行配置
# 当然,理论上的并发总数可能会和实际有所偏差,因为主机还有其他的工作进程需要消耗系统资源。
# ulimit -SHn 65535
}
http {
#设定 mime 类型,类型由 mime.type 文件定义
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;
#sendfile 指令指定 nginx 是否调用 sendfile 函数( zero copy 方式)来输出文件,
#对于普通应用,必须设为 on,
#如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off,
#以平衡磁盘与网络 I/O 处理速度,降低系统的 uptime.
sendfile on;
#tcp_nopush on;
#连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

#开启 gzip 压缩
gzip on;
gzip_disable "MSIE [1-6].";
#nginx 传输文件大小,默认为1M

client_max_body_size 20m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;

#设定请求缓冲
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;

#设定虚拟主机配置
server {
#侦听 80 端口
listen 80;
#定义使用 www.linuxidc.com 访问
server_name www.linuxidc.com;
#定义服务器的默认网站根目录位置
root html;
#设定本虚拟主机的访问日志
access_log logs/nginx.access.log main;
#默认请求
location / {
#定义首页索引文件的名称
index index.php index.html index.htm;
}
# 定义错误提示页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
} #
静态文件, nginx 自己处理
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
#过期 30 天,静态文件不怎么更新,过期可以设大一点,
#如果频繁更新,则可以设置得小一点。
expires 30d;
}
#PHP 脚本请求全部转发到 FastCGI 处理. 使用 FastCGI 默认配置.

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} #
禁止访问 .htxxx 文件
location ~ /.ht {
deny all;
}
}
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值