跳至主要內容

文档站点部署到服务器

牧歌2024年11月14日...大约 3 分钟

文档站点部署到服务器

直接使用 Nginx 转发

安装 Nginx

方便使用 yum

yum install nginx

显示如下效果即为安装成功

=======================================================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 2.4 M
Installed size: 6.7 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): gperftools-libs-2.6.1-1.el7.x86_64.rpm                                                                                                   | 272 kB  00:00:00     
(2/5): centos-indexhtml-7-9.el7.centos.noarch.rpm                                                                                               |  92 kB  00:00:00     
(3/5): nginx-1.20.1-10.el7.x86_64.rpm                                                                                                           | 588 kB  00:00:00     
(4/5): nginx-filesystem-1.20.1-10.el7.noarch.rpm                                                                                                |  24 kB  00:00:00     
(5/5): openssl11-libs-1.1.1k-7.el7.x86_64.rpm                                                                                                   | 1.5 MB  00:00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                  4.2 MB/s | 2.4 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:openssl11-libs-1.1.1k-7.el7.x86_64                                                                                                                1/5 
  Installing : 1:nginx-filesystem-1.20.1-10.el7.noarch                                                                                                             2/5 
  Installing : centos-indexhtml-7-9.el7.centos.noarch                                                                                                              3/5 
  Installing : gperftools-libs-2.6.1-1.el7.x86_64                                                                                                                  4/5 
  Installing : 1:nginx-1.20.1-10.el7.x86_64                                                                                                                        5/5 
  Verifying  : gperftools-libs-2.6.1-1.el7.x86_64                                                                                                                  1/5 
  Verifying  : centos-indexhtml-7-9.el7.centos.noarch                                                                                                              2/5 
  Verifying  : 1:nginx-filesystem-1.20.1-10.el7.noarch                                                                                                             3/5 
  Verifying  : 1:nginx-1.20.1-10.el7.x86_64                                                                                                                        4/5 
  Verifying  : 1:openssl11-libs-1.1.1k-7.el7.x86_64                                                                                                                5/5 

Installed:
  nginx.x86_64 1:1.20.1-10.el7                                                                                                                                         

Dependency Installed:
  centos-indexhtml.noarch 0:7-9.el7.centos   gperftools-libs.x86_64 0:2.6.1-1.el7   nginx-filesystem.noarch 1:1.20.1-10.el7   openssl11-libs.x86_64 1:1.1.1k-7.el7  

Complete

安装完成后,Nginx的各个目录分别如下:

配置文件所在目录:
	主配置文件:/etc/nginx/nginx.conf
	网站配置文件目录:/etc/nginx/conf.d/
	默认站点配置文件目录:/etc/nginx/default.d/

网站文件所在目录
	默认站点目录:/usr/share/nginx/html/

日志文件所在目录:
	错误日志目录:/var/log/nginx/
	访问日志目录:/var/log/nginx/

可执行文件所在目录(nginx就是执行文件):/usr/sbin/nginx

备份和修改nginx.conf

cd /etc/nginx
cp nginx.conf nginx.conf_bak

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

    server {
        listen       80;
        server_name  localhost;
        root        /usr/share/nginx/html/dist;
        index        index.html;

        location /life-doc/ {
            proxy_pass http://localhost:80/;
			proxy_buffer_size 1024k;
			proxy_buffers 16 1024k;
			proxy_busy_buffers_size 2048k;
			proxy_temp_file_write_size 2048k;
        }

        location /waline/ {
            proxy_pass http://150.158.58.15:8361/; # Waline 服务器的 URL
			proxy_buffer_size 1024k;
            proxy_buffers 16 1024k;
            proxy_busy_buffers_size 2048k;
            proxy_temp_file_write_size 2048k;
        }
	# 这里是新增的 gzip 配置
	gzip on;
	gzip_min_length 1k;
	gzip_buffers 4 16k;
	gzip_comp_level 6;
	gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml image/jpeg image/gif image/png;
	gzip_vary off;
	gzip_disable "MSIE [1-6]\.";
    }

    # 添加https server
    server {
        # 监听443端口,开始 ssl
        listen       443 ssl;
        # 域名
        server_name  wenlei.wang;
        # 证书路径
		ssl_certificate   /etc/nginx/cert/sslconfigure.pem; # 这个目录需要替换成你自己证书的存放目录
		ssl_certificate_key  /etc/nginx/cert/sslconfigure.key; # 这个目录需要替换成你自己证书的存放目录
		#SSL-END SSL相关配置
		ssl_session_timeout 5m;
		ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 由于 TLS v1存在不安全的算法,如果需要较高安全需要把 TLS v1删除
		ssl_prefer_server_ciphers on;

		location / {
			proxy_pass http://localhost:80/;
			proxy_buffer_size 1024k;
			proxy_buffers 16 1024k;
			proxy_busy_buffers_size 2048k;
			proxy_temp_file_write_size 2048k;
		}
		location /sitemap.xml {
			proxy_pass http://localhost:80/sitemap.xml;
			proxy_buffer_size 1024k;
			proxy_buffers 16 1024k;
			proxy_busy_buffers_size 2048k;
			proxy_temp_file_write_size 2048k;
		}
		location /life-doc/sitemap.xml {
			proxy_pass http://localhost:80/sitemap.xml;
			proxy_buffer_size 1024k;
			proxy_buffers 16 1024k;
			proxy_busy_buffers_size 2048k;
			proxy_temp_file_write_size 2048k;
		}
		location /life-doc/ {
			proxy_pass http://localhost:80/;
			
			proxy_buffer_size 1024k;
			proxy_buffers 16 1024k;
			proxy_busy_buffers_size 2048k;
			proxy_temp_file_write_size 2048k;
		}

		location /waline/ {
			proxy_pass http://59.110.90.215:8361/; # Waline 服务器的 URL
			proxy_buffer_size 1024k;
            proxy_buffers 16 1024k;
            proxy_busy_buffers_size 2048k;
            proxy_temp_file_write_size 2048k;
		}

		# 这里是新增的 gzip 配置
		gzip on;
		gzip_min_length 1k;
		gzip_buffers 4 16k;
		gzip_comp_level 6;
		gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml image/jpeg image/gif image/png;
		gzip_vary off;
		gzip_disable "MSIE [1-6]\.";

	}

}

验证配置文件是否正确

/usr/sbin/nginx -t

启动Nginx

systemctl start nginx.service

看下是否启动成功如果展示,如下running内容表示成功

systemctl status nginx.service 
[root@iZ2zeczbp1cst7yps65s8kZ etc]# systemctl status nginx.service 
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-11-14 15:58:50 CST; 10s ago
  Process: 3280 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 3277 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 3275 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 3283 (nginx)
    Tasks: 2
   Memory: 1.6M
   CGroup: /system.slice/nginx.service
           ├─3283 nginx: master process /usr/sbin/nginx
           └─3284 nginx: worker process

Nov 14 15:58:50 iZ2zeczbp1cst7yps65s8kZ systemd[1]: Starting The nginx HTTP and reverse proxy server...
Nov 14 15:58:50 iZ2zeczbp1cst7yps65s8kZ nginx[3277]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 14 15:58:50 iZ2zeczbp1cst7yps65s8kZ nginx[3277]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 14 15:58:50 iZ2zeczbp1cst7yps65s8kZ systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@iZ2zeczbp1cst7yps65s8kZ etc]# 

打包上传项目

将打包的项目上传至 /usr/share/nginx/html/ 文件夹下,这个文件夹在配置文件 root 配置的

上次编辑于: 2024/11/15 09:35:46
贡献者: wenleiwang
评论
  • 按正序
  • 按倒序
  • 按热度