ubuntu_20_04_x64_20G_alibase 20 阿里云部署nginx

2020年的双十一单身狗的节日,那就买一台云服务器来玩玩吧!于是就有了这篇文章了,以及其他的一系列文章了。本人是初学者,有不对的地方欢迎指正。也欢迎留言交流。

 

1.更新软件列表

apt-get update

2、安装软件

apt-get install nginx

3、进入sites-enabled 这个目录

cd /etc/nginx/sites-enabled 

4、修改default文件,修改端口改成8085(默认为80,不一定是8085也可以说其他不常见的端口)

root@123:/etc/nginx/sites-enabled# vi default 
##
# You should look at the following URL’s in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or WordPress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 8085 default_server;
    listen [::]:8085 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # 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;
    }

    # 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.4-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;
    #}
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#    listen 80;
#    listen [::]:80;
#
#    server_name example.com;
#
#    root /var/www/example.com;
#    index index.html;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#}

输入i(小写)进入编辑模式,修改端口为8085,上面红色部分,然后按esc键,在输入wq回车保存。

 

 

 

 

——————————————————————————————————————————————-

两个长横线之间的问题可以跳过,这些是一些配置过程中的小插曲,导致我出现一些问题,顺便记录下来吧

如果不修改重启会出现以下错误:

# service nginx restart
Job for nginx.service failed because the control process exited with error code.
See “systemctl status nginx.service” and “journalctl -xe” for details.

查看80端口,可以看到已经被其他端口占用了,因此需要更改为上面说的8085

# lsof -i:80
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
AliYunDun 456 root   20u  IPv4 789 0t0  TCP 123:60002->103.104.31.21:http (ESTABLISHED)
root@123:/etc/nginx/conf.d# vi default.conf 

 

按照其他博客说的,在部署需要的web服务时,我们可以拷贝/etc/nginx/sites-enabled中的default文件到conf.d并且修改名字为**.conf 然后进行配置,但我测试过还是不行。

#systemctl status nginx.service
● nginx.service – A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-11-15 23:36:26 CST; 22s ago
       Docs: man:nginx(8)
    Process: 12132 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, statu>

Nov 15 23:36:26 123 systemd[1]: Starting A high performance web server and a reverse p>
Nov 15 23:36:26 123 nginx[12132]: nginx: [emerg] a duplicate default server for 0.0.0.>
Nov 15 23:36:26 123 nginx[12132]: nginx: configuration file /etc/nginx/nginx.conf test>
Nov 15 23:36:26 123 systemd[1]: nginx.service: Control process exited, code=exited, st>
Nov 15 23:36:26 123 systemd[1]: nginx.service: Failed with result ‘exit-code’.
Nov 15 23:36:26 123 systemd[1]: Failed to start A high performance web server and a re>
lines 1-12/12 (END)

● nginx.service – A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-11-15 23:36:26 CST; 22s ago
       Docs: man:nginx(8)
    Process: 12132 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Nov 15 23:36:26 123 systemd[1]: Starting A high performance web server and a reverse proxy server…
Nov 15 23:36:26 123 nginx[12132]: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-en>
Nov 15 23:36:26 123 nginx[12132]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 15 23:36:26 123 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Nov 15 23:36:26 123 systemd[1]: nginx.service: Failed with result ‘exit-code’.
Nov 15 23:36:26 123 systemd[1]: Failed to start A high performance web server and a reverse proxy server.

————————————————————————————————————————————–

 

 

 

 

5、重启nginx 

service nginx restart

6、设置访问权限

阿里云部署mosquitto时一直连接不上,原来是端口没有开放,没有访问权限。

如果不能访问,那就是你的服务器安全组没有允许8085该端口访问,配置把8085端口为允许访问即可,图片是显示的是1883,实际上是你上面配置的端口,我的是8085

 

ubuntu_20_04_x64_20G_alibase 20 阿里云部署nginx

ubuntu_20_04_x64_20G_alibase 20 阿里云部署nginx

7.在浏览器输入你的iP加端口

比如:47.102.105.106:8085,回车,如果出现下面这个图片,那么你成功了。

ubuntu_20_04_x64_20G_alibase 20 阿里云部署nginx

 

 

参考自:

https://www.cnblogs.com/the-wang/p/9034861.html

https://www.cnblogs.com/gede/p/11011693.html

https://segmentfault.com/a/1190000015797789

https://blog.csdn.net/weixin_42726818/article/details/90694387

https://blog.csdn.net/cckavin/article/details/85113373

 

文章知识点与官方知识档案匹配,可进一步学习相关知识云原生入门技能树云原生环境小结云原生的分层8597 人正在系统学习中

来源:斗转星移3

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年10月12日
下一篇 2020年10月13日

相关推荐