linux使用系统包安装nginx

2023-05-26 08:54:10 浏览数 (2)

本文系统为

Ubuntu 18.04.6 LTS

默认安装的nginx为

nginx/1.14.0 (Ubuntu)

安装

代码语言:shell复制
apt install nginx -y

配置文件目录

代码语言:shell复制
cd /etc/nginx/
配置配置

网站目录

代码语言:javascript复制
cd /var/www/
网站网站

修改配置

修改/etc/nginx/nginx.conf

修改62行

代码语言:javascript复制
	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-available/*;

反代配置

默认网站

如果未绑定的域名或ip会自动跳到这个网站

代码语言:javascript复制
server {
    listen 80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}

反代多个网站

网站1

代码语言:javascript复制
server {
    listen 80;
    server_name demo.xxx.love;
    location / {
        proxy_pass http://localhost:9000/;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
    }
}

网站2

代码语言:javascript复制
server {
    listen 80;
    server_name demo2.xxx.love;
    location / {
        proxy_pass http://localhost:9000/;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
    }
}

ssl

代码语言:javascript复制
server {
    listen 80;
    listen 443 ssl;
    server_name pay.xxx.love;
    ssl_certificate /etc/nginx/cert.pem;
    ssl_certificate_key /etc/nginx/key.pem;
    location /auth {
        root /var/www/faka;
        index index.html;
    }
    if ($scheme != "https") {
        return 301 https://$server_name$request_uri;
    }
    location / {
        proxy_pass http://localhost:8009/;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
    }
}

其它命令

代码语言:javascript复制
systemctl status nginx
systemctl stop nginx
systemctl start nginx
systemctl restart nginx
systemctl enable nginx

0 人点赞