隐藏页面特效

服务器安装Nginx

1|0环境


  • CentOS 8
  • 使用编译安装 Nginx

1|1Nginx使用Docker安装确实有点麻烦,需要将很多前端文件映射到容器内部,不推荐


2|0正式环境


1、安装环境需要的依赖包

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

2、在你的linux服务器上创建目录:nginx

cd /root && mkdir nginx

3、进入刚才安装的目录

cd nginx

4、下载并且解压安装包

wget http://nginx.org/download/nginx-1.13.7.tar.gz && tar -zxvf nginx-1.13.7.tar.gz  

5、进入刚刚解压好的目录

cd nginx-1.13.7

6、添加一些常用的模块,比如:gzip、https 模块

./configure --with-http_gzip_static_module --with-http_stub_status_module  --with-http_stub_status_module --with-http_ssl_module

7、 执行下面的命令

make && make install

make指令报错解决办法:https://blog.csdn.net/qq_45697992/article/details/120028370

8、设置 Linux 环境变量

1)编辑 /etc/profile 文件

vi /etc/profile

2)在最后一行添加下面的代码

PATH=$PATH:/usr/local/nginx/sbin
export PATH

3)让配置生效

source /etc/profile

9、任意目录下输入

nginx

10、访问服务器 IP

curl http://localhost

3|0Nginx 常用命令


按照上面安装之后,nginx 的位置在哪里?

/usr/local/nginx/sbin

1、检查 Nginx 配置文件的语法

nginx -t

2、显示 Nginx 版本信息

nginx -v

3、查看编译时的配置参数 (大写的 V)

nginx -V

4、重启 Nginx

nginx -s stop

5、重新加载配置文件

nginx -s reload


如果出现上面的报错,就检查一下 nginx 配置文件

4|0Nginx配置文件


#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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

}

5|0遇到的报错


当输入 nginx -s reload 时报错 nginx: [error] invalid PID number

解决:

sudo pkill -f nginx

强制删除 Nginx 进程,然后再重新启动

nginx


__EOF__

本文作者techgy
本文链接https://www.cnblogs.com/techgy/p/18716020.html
关于博主:I am a good person
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   AI未来10Y  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
点击右上角即可分享
微信分享提示