【2.14】服务器安装 Linux中安装 Nginx

方法1

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
yum install nginx -y

方法2 推荐

去官网下载最新的tar包

image.png

安装 webget
yum install wget

#0.下载源码安装包
wget http://nginx.org/download/nginx-1.23.1.tar.gz

# 1.解压
tar -zxvf nginx-1.23.1.tar.gz

# 2.进入刚解压的目录
cd nginx-1.23.1
    
#3.使用nginx默认配置安装
./configure
    
#4.安装
make &&make install

#5.查找安装路径
whereis nginx
    
#6.进入目录
cd /usr/local/nginx/sbin
 
#7 配置端口和 php支持和反向代理、ssl等
vim /usr/local/nginx/conf/nginx.conf
 

#8.启动nginx
./nginx
    
#9.查看是否启动
ps -ef | grep nginx
    
#安装完成
nginx.conf 修改

php支持版本 其他反向代理查看【3.5】服务器安装 Docker中安装与配置 Nginx 的conf/default.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       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        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen      9099 ;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php; # 这里添加 index.php
        }

        #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:9300; # 这里我的php使用的9300 需要注意
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$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;
    #    }
    #}

}

浏览器访问 IP:端口


image.png

创建phpinfo文件

mkdir  /usr/local/nginx/html/php
echo "" > /usr/local/nginx/html/php/phpinfo.php

访问 IP:9099/php/phpinfo.php


image.png

配制环境变量
vi /etc/profile

# 添加nginx的路径
export PATH=$PATH:/usr/local/nginx/sbin

你可能感兴趣的:(【2.14】服务器安装 Linux中安装 Nginx)