Sometimes local development requires debugging of static file resources that cannot be accessed directly. This can be done by configuring the local Nginx service. By the way, the configuration steps of Nginx are recorded. Install <!--Install via Brew: --> brew install nginx <!--Start: --> brew services start nginx <!--View configuration: --> cat usr/local/etc/nginx/nginx.conf <!--Edit configuration: --> vi usr/local/etc/nginx/nginx.conf Nginx command: <!--Start: --> nginx <!--Stop/Restart--> nginx -s stop/start/restart Configuration Files File address: usr/local/etc/nginx/nginx.conf # Only root owner can access root's static files, otherwise 403 will be reported user root owner; 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; #gzip on; server { # Listen port listen 8080; # Bind domain name server_name local.XXX.com; #charset koi8-r; #access_log logs/host.access.log main; #File path and entry file location / { root /usr/local/var/www; index index.html index.htm; } # Interface resource 1 location /XXXapi/ { proxy_pass https://api.XXX.com; } # Interface resource 2 location /apiXXX/ { proxy_pass https://api.XXX.com; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include servers/*; } Configuration steps
# Listen port listen 8080; # Bind domain name server_name local.XXX.com; Specify the entry file and static file path#File path and entry file location / { root /usr/local/var/www; index index.html index.htm; } If there are additional API resources, bind the corresponding API resource address through proxy_pass# Interface resource 1 location /XXXapi/ { proxy_pass https://api.XXX.com; } # Interface resource 2 location /apiXXX/ { proxy_pass https://api.XXX.com; }
This is the end of this article about Nginx configuration in Mac environment and the implementation of accessing local static resources. For more relevant content about Nginx configuration and accessing local static resources, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Web project development JS function anti-shake and throttling sample code
>>: How to install MySQL 5.7.29 with one click using shell script
Many friends found that the box model is a square...
Project requirements require some preprocessing o...
Question: How to achieve a rounded rectangle usin...
This article shares the specific code of javascri...
What is an index? Why create an index? Indexes ar...
Use OSS to upload pictures or attachments in vue ...
Table of contents Congruent and Incongruent congr...
Problem Description Today, when I was modifying t...
sudo configuration file The default configuration...
Preface Due to the needs of the company's bus...
Xiaobai records the installation of vmtools: 1. S...
Many tables in MySQL contain columns that can be ...
For more exciting content, please visit https://g...
Simple function: Click the plug-in icon in the up...
Preview versions of Safari (Technology Preview 10...