CentOS7 server 安装 nginx 与配置施例

本篇属于备忘形式的记录,系统环境是在PVE集群中开启新Centos7 的虚拟机,配置网络环境和安装nginx过程记录。

配置网络

[root@localhost logs]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp   # dhcp 客户端
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes	# 配置开机启动网卡

DNS2=114.114.114.114
DNS1=8.8.4.4

配置 nginx 安装源

[root@localhost logs]# cat /etc/yum.repos.d/nginx.repo 
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

[root@localhost logs]# 

安装 nginx

进入root角色,安装 nginx 。

[root@localhost logs]# yum install -y nginx

配置 nginx

配置文件 /etc/nginx/nginx.conf

[root@localhost logs]# cat /etc/nginx/nginx.conf
user  robot;

worker_processes auto;
worker_cpu_affinity auto;

error_log  /tmp/nginx_error.log  crit;

#pid        /usr/local/nginx/logs/nginx.pid;
pid /var/run/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
    
    
        use epoll;
        worker_connections 51200;
        multi_accept off;
        accept_mutex off;
    }

http
    {
    
    
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile on;
        sendfile_max_chunk 512k;
        tcp_nopush on;

        keepalive_timeout 60;
	client_header_timeout 5;
	client_body_timeout 10;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
    
    
        listen 80 default_server reuseport;
        server_name crm;
        index index.html index.htm index.php;
        root  /home/robot/vue-web/dist/;
	try_files $uri $uri/ /index.html;

	location /api/ {
    
    
            proxy_read_timeout 30;	#second
            proxy_pass http://192.168.15.160:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-Port $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        access_log  /tmp/access.log;
    }

include vhost/*.conf;
}

重启 nginx

systemctl restart nginx.service

关闭防火墙

systemctl disable --now firewalld

验证服务

用curl 验证nginx

robot@ubuntu:~$ curl http://192.168.90.176
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>rosv</title>
<link href=/static/css/app.1a1dcdddb20c883441e636dc44f9240f.css rel=stylesheet></head><body>
<div id=app></div><script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js>
</script><script type=text/javascript src=/static/js/vendor.ce134fd501d292610566.js></script>
<script type=text/javascript src=/static/js/app.b28e63d20f74bea7edcc.js>
</script></body></html>

robot@ubuntu:~$ 

猜你喜欢

转载自blog.csdn.net/weixin_38387929/article/details/119908665
今日推荐