Centos7 yumをnginxのソースのインストールと設定は、nginxのを記述する

Centos7 yumをnginxのソースのインストールと設定は、nginxのを記述する

(1)インストール

1.1追加nginxのリポジトリ
yum install epel-release
1.2インストールnginxのを開始
yum install nginx

これら二つのコマンドの真ん中には、あなただけのすべての方法のyyyyyyyyyyyを継続する必要があるかどうかを求めるプロンプトが表示されます

ここでnginxの既にインストールされています

警告を開始1.3nginx

1.nginxポートが占有されているかどうか、nginxのデフォルトのポートはポート80です

2. 80ポートサーバが保護壁とオープン対応するセキュリティグループになっています

その後、セキュリティグループを設定するコマンドオープンファイアウォールポートの下で80、クラウドサーバは、アリクラウドやクラウドテンセントオープンセキュリティグループをログインする必要があります

firewall-cmd --zone=public --add-port=80/tcp --permanent

起動してみてください!

nginxのは、一般的に使用されるコマンドが付属しています

#启动nginx  两种命令都可以启动
systemctl start nginx   
nginx

#设置nginx开机启动
systemctl enable nginx

#卸载nginx命令
yum remove nginx

#停止nginx
nginx -s stop

#重启nginx
nginx -s reload

デフォルトのポートを変更しない場合はnginxのnginxのサーバーIPへの直接アクセスを開始する(80デフォルトでは書き込むことはできません)することができます、あなたはサーバーIPのデフォルトポートのアクセス方法を変更した場合:nginxのポートを

プロンプト説明nginxのでページが表示されますを訪問した後、正常にインストールされ、開始されました

Welcome to CentOS
The Community ENTerprise Operating System

(2)nginxの設定

yumのデフォルト設定nginxのソース設置位置を使用して

/etc/nginx/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;
#启动进程,每个Nginx进程平均耗费10M~12M内存。建议指定和CPU的数量一致即可
worker_processes auto;
#全局错误日志及PID文件
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
#工作模式
events {
	#单个后台worker process进程的最大并发链接数
    worker_connections 1024;
}
#http服务器,负载均衡以及反向代理都是使用它
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;
    
	#设定mime类型,类型由mime.type文件定义
    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 块是对虚拟主机的配置,server标志定义虚拟主机开始
    server {
    	#listen用于指定虚拟主机的服务端口,启动后就是虚拟机ip+此指定的端口进行访问
        listen       80 default_server;
        listen       [::]:80 default_server;
        #server_name 用来指定IP地址或域名,多个域名之间用空格分开
        server_name  _;
        #root指令用于指定虚拟主机的网页根目录,这个目录可以是相对路径,也可以是绝对路径
        root         /usr/share/nginx/html;

        #加载默认服务器组的配置文件.
        include /etc/nginx/default.d/*.conf;
		#location块
		#URL地址匹配 /a  访问就ip:端口/a 
		#下方location是我自己目前的配置
		#在一个server中 可以配置多个location ,但是“/“必须有一个
        location / {
        #ftp文件主目录,只允许有一个
        root /var/ftp/pub/;
        #此访问的首页
        index index.html index.htm index.php index.jpg index.mp4 index.txt;
        }
        #404页
        error_page 404 /404.html;
            location = /40x.html {
        }
		#500页
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        #第二个location
        location /chexuan/ {
        alias /ftp/chexuan/;
        index index.html index.htm index.php index.jpg index.mp4 index.txt;
        }

        #举例
        #访根目录/, 比如http://localhost/ 就会匹配 /var/ftp/pub/下的index文件
        #访问目录/chexuan/  比如http://localhost/chexuan/ 就会匹配 /ftp/chexuan/下的index文件
    }

# 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 {
#        }
#    }

}


前記ルート及びエイリアス・ロケーション・コード・ブロックとの間の差

root实例:

location /t/ {
     root /www/root/html/;
}
如果一个请求的URI是/t/a.html时,web服务器将会返回服务器上的/www/root/html/t/a.html的文件。

alias实例:

location /t/ {
 alias /www/root/html/leilei/;
}
如果一个请求的URI是/t/a.html时,web服务器将会返回服务器上的/www/root/html/leilei/a.html的文件。注意这里是leilei,因为alias会把location后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录。


注意

  1. エイリアスを使用する場合は、ディレクトリ名を追加する必要があり、「/。」
  2. 別名定期的に試合を使用して、指定されたコンテンツにマッチして使用されるコンテンツを取得する必要があります。
  3. エイリアスは、位置ブロックに配置することができます。(ルートは、場所に配置することができません)

nginxのは、現在、学習、そして、この目的を綿密なフォローアップ時にアップデートを継続されます

公開された29元の記事 ウォン称賛22 ビュー3487

おすすめ

転載: blog.csdn.net/leilei1366615/article/details/104055134