【问题标题】:Failed to start high performance web server and reverse proxy server nginx启动高性能web服务器和反向代理服务器nginx失败
【发布时间】:2020-08-18 21:35:47
【问题描述】:

更新 - 我收到了这些错误日志:

nginx: [emerg] unknown "request_url" variable
Aug 19 01:14:58 nginx[4890]: nginx: 
configuration file /etc/nginx/nginx.conf test failed

这是我的 nginx.conf 文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript 
text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

错误的“请求网址”部分可能在我的启用站点/默认文件中靠近底部的位置块中:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name         www.domainname;
    ssl_certificate     /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    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;

            return 301 https://www.hobyn.co$request_url;

原始问题 - 运行时启动高性能 Web 服务器和反向代理服务器失败:

sudo /etc/init.d/nginx restart

在对我的 /etc/nginx/sites-available/default 文件进行以下服务器块配置后重新启动 nginx。我的 Angular 应用程序正在 /var/www/html 中提供:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name         www.mydomainname;
    ssl_certificate     /etc/nginx/ssl/****.crt;
    ssl_certificate_key /etc/nginx/ssl/****.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;


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

            return 301 https://www.mydomainname$request_url;
    }

【问题讨论】:

    标签: angular ubuntu ssl nginx digital-ocean


    【解决方案1】:

    我在这里修复了此配置的错误:

    server {
        # SSL configuration
        #
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl default_server;
        server_name domainname www.domainname;
        ssl on;
        ssl_certificate     /etc/nginx/ssl/server.crt;
        ssl_certificate_key /etc/nginx/ssl/server.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
    
        proxy_set_header X_FORWARDED_PROTO https;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header  Host $http_host;
        proxy_set_header  X-Url-Scheme $scheme;
        proxy_redirect    off;
        proxy_max_temp_file_size 0;
        #
        # Note: You should disable gzip for SSL traffic. See: 
          https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
    
        root /var/www/html;
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
        }
    
        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
    }
    
    server {
    
      listen 80;
      listen [::]:80;
      server_name hobyn.co www.hobyn.co;
      return 301 https://hobyn.co$request_uri;
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-05
      • 2020-04-19
      • 1970-01-01
      • 2017-08-16
      • 2017-03-01
      • 1970-01-01
      • 2020-09-22
      • 2017-07-17
      • 2020-06-29
      相关资源
      最近更新 更多