Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx 配置文件 #2

Open
adodo0829 opened this issue Feb 12, 2020 · 0 comments
Open

nginx 配置文件 #2

adodo0829 opened this issue Feb 12, 2020 · 0 comments

Comments

@adodo0829
Copy link
Owner

nginx.conf 文件

nginx.conf 文件是Nginx的总配置文件,我们可以按需进行修改

# 运行用户,默认即是nginx,可以不进行设置
user  nginx;
# nginx进程,一般设置为和CPU核数一样
worker_processes  1;   
# 错误日志存放目录
error_log  /var/log/nginx/error.log warn;
# 进程pid存放位置
pid        /var/run/nginx.pid;


events {
    worker_connections  1024; # 单个后台进程的最大并发数
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;   #nginx访问日志存放位置

    sendfile        on;   #开启高效传输模式
    #tcp_nopush     on;    #减少网络报文段的数量

    keepalive_timeout  65;  #保持连接的时间,也叫超时时间

    #gzip  on;  #开启gzip压缩

    include /etc/nginx/conf.d/*.conf; #包含的子配置项位置和文件

上述子配置文件

我们创建一个 default.conf 文件

server {
    listen       80;   #配置监听端口
    server_name  localhost;  //配置域名

    #charset koi8-r;     
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;     #服务默认启动目录
        index  index.html index.htm;    #默认访问文件
    }

    #error_page  404              /404.html;   # 配置404页面

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;   #错误状态码的显示页面,配置后需要重启
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

vue 项目部署到服务器

server {
    listen 80;
    server_name xxxx.com;
    error_log /logs/xxxx.com-errorlog.log;
    location / {
        root /www/xxxx/dist; 
        # index index.html; # hash 模式
        try_files $uri $uri/ /index.html; # history 模式
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant